<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)
                

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

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

                相关文档推荐

                What happens when you compare 2 pandas Series(当你比较 2 个 pandas 系列时会发生什么)
                Quickly find differences between two large text files(快速查找两个大文本文件之间的差异)
                Python - Compare 2 files and output differences(Python - 比较 2 个文件和输出差异)
                Why do comparisions between very large float values fail in python?(为什么在 python 中非常大的浮点值之间的比较会失败?)
                Dictionary merge by updating but not overwriting if value exists(字典通过更新合并,但如果值存在则不覆盖)
                Find entries of one text file in another file in python(在python中的另一个文件中查找一个文本文件的条目)
              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>