<small id='Z3AKy'></small><noframes id='Z3AKy'>

  1. <i id='Z3AKy'><tr id='Z3AKy'><dt id='Z3AKy'><q id='Z3AKy'><span id='Z3AKy'><b id='Z3AKy'><form id='Z3AKy'><ins id='Z3AKy'></ins><ul id='Z3AKy'></ul><sub id='Z3AKy'></sub></form><legend id='Z3AKy'></legend><bdo id='Z3AKy'><pre id='Z3AKy'><center id='Z3AKy'></center></pre></bdo></b><th id='Z3AKy'></th></span></q></dt></tr></i><div id='Z3AKy'><tfoot id='Z3AKy'></tfoot><dl id='Z3AKy'><fieldset id='Z3AKy'></fieldset></dl></div>

  2. <legend id='Z3AKy'><style id='Z3AKy'><dir id='Z3AKy'><q id='Z3AKy'></q></dir></style></legend>
    • <bdo id='Z3AKy'></bdo><ul id='Z3AKy'></ul>

      <tfoot id='Z3AKy'></tfoot>
    1. 在列表中查找最旧/最年轻的日期时间对象

      Find oldest/youngest datetime object in a list(在列表中查找最旧/最年轻的日期时间对象)
        <bdo id='x8ozQ'></bdo><ul id='x8ozQ'></ul>

              <tbody id='x8ozQ'></tbody>

              <small id='x8ozQ'></small><noframes id='x8ozQ'>

                <i id='x8ozQ'><tr id='x8ozQ'><dt id='x8ozQ'><q id='x8ozQ'><span id='x8ozQ'><b id='x8ozQ'><form id='x8ozQ'><ins id='x8ozQ'></ins><ul id='x8ozQ'></ul><sub id='x8ozQ'></sub></form><legend id='x8ozQ'></legend><bdo id='x8ozQ'><pre id='x8ozQ'><center id='x8ozQ'></center></pre></bdo></b><th id='x8ozQ'></th></span></q></dt></tr></i><div id='x8ozQ'><tfoot id='x8ozQ'></tfoot><dl id='x8ozQ'><fieldset id='x8ozQ'></fieldset></dl></div>
                <tfoot id='x8ozQ'></tfoot>

                <legend id='x8ozQ'><style id='x8ozQ'><dir id='x8ozQ'><q id='x8ozQ'></q></dir></style></legend>

              1. 本文介绍了在列表中查找最旧/最年轻的日期时间对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                I've got a list of datetime objects, and I want to find the oldest or youngest one. Some of these dates might be in the future.

                from datetime import datetime
                
                datetime_list = [
                    datetime(2009, 10, 12, 10, 10),
                    datetime(2010, 10, 12, 10, 10),
                    datetime(2010, 10, 12, 10, 10),
                    datetime(2011, 10, 12, 10, 10), #future
                    datetime(2012, 10, 12, 10, 10), #future
                ]
                

                What's the most optimal way to do so? I was thinking of comparing datetime.now() to each one of those.

                解决方案

                Oldest:

                oldest = min(datetimes)
                

                Youngest before now:

                now = datetime.datetime.now(pytz.utc)
                youngest = max(dt for dt in datetimes if dt < now)
                

                这篇关于在列表中查找最旧/最年轻的日期时间对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                groupby multiple coords along a single dimension in xarray(在xarray中按单个维度的多个坐标分组)
                Group by and Sum in Pandas without losing columns(Pandas中的GROUP BY AND SUM不丢失列)
                Group by + New Column + Grab value former row based on conditionals(GROUP BY+新列+基于条件的前一行抓取值)
                Groupby and interpolate in Pandas(PANDA中的Groupby算法和插值算法)
                Pandas - Group Rows based on a column and replace NaN with non-null values(PANAS-基于列对行进行分组,并将NaN替换为非空值)
                Grouping pandas DataFrame by 10 minute intervals(按10分钟间隔对 pandas 数据帧进行分组)
              2. <small id='LRpul'></small><noframes id='LRpul'>

                  <legend id='LRpul'><style id='LRpul'><dir id='LRpul'><q id='LRpul'></q></dir></style></legend>
                  • <bdo id='LRpul'></bdo><ul id='LRpul'></ul>
                  • <tfoot id='LRpul'></tfoot>
                          <tbody id='LRpul'></tbody>
                        <i id='LRpul'><tr id='LRpul'><dt id='LRpul'><q id='LRpul'><span id='LRpul'><b id='LRpul'><form id='LRpul'><ins id='LRpul'></ins><ul id='LRpul'></ul><sub id='LRpul'></sub></form><legend id='LRpul'></legend><bdo id='LRpul'><pre id='LRpul'><center id='LRpul'></center></pre></bdo></b><th id='LRpul'></th></span></q></dt></tr></i><div id='LRpul'><tfoot id='LRpul'></tfoot><dl id='LRpul'><fieldset id='LRpul'></fieldset></dl></div>