Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #75980

Re:get the min date from a list

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'rename': 0.07; 'string': 0.09; 'converts': 0.09; 'objects,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.11; 'assume': 0.14; 'wrote': 0.14; '.........': 0.16; 'received:80.91.229.3': 0.16; 'received:97': 0.16; 'received:plane.gmane.org': 0.16; 'simplest': 0.16; 'sorting': 0.16; 'do,': 0.16; '>>>': 0.22; '+0000': 0.22; 'aug': 0.22; 'documented': 0.24; 'specify': 0.24; 'string,': 0.24; 'least': 0.26; 'header:X-Complaints-To:1': 0.27; 'function': 0.29; 'testing': 0.29; 'subject:list': 0.30; 'code': 0.31; 'assumes': 0.31; 'probably': 0.32; 'subject:the': 0.34; 'subject:from': 0.34; 'but': 0.35; 'dates': 0.36; 'object,': 0.36; "didn't": 0.36; "i'll": 0.36; 'should': 0.36; 'list': 0.37; 'minimum': 0.38; 'version,': 0.38; 'to:addr:python-list': 0.38; 'list,': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'name': 0.63; 'subject:get': 0.81; '2.5.': 0.84; 'min': 0.84; 'subject::': 0.85
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Dave Angel <davea@davea.name>
Subject Re:get the min date from a list
Date Sun, 10 Aug 2014 07:02:49 -0400 (EDT)
Organization news.gmane.org
References <53E71BCB.7060307@gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host 97.73.240.8
X-Newsreader PiaoHong.Usenet.Client.VIP:1.56
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.12816.1407668534.18130.python-list@python.org> (permalink)
Lines 45
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1407668534 news.xs4all.nl 2898 [2001:888:2000:d::a6]:43003
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:75980

Show key headers only | View raw


luofeiyu <elearn2014@gmail.com> Wrote in message:
>  >>> date
> ['Sat, 09 Aug 2014 07:36:46 -0700', 'Fri, 8 Aug 2014 22:25:40 -0400', 
> 'Sat, 9 Au
> g 2014 12:46:43 +1000', 'Sat, 9 Aug 2014 12:50:52 +1000', 'Sat, 9 Aug 
> ......... 
> 2014 03:4
> 4:56 +0200', 'Sun, 10 Aug 2014 01:55:24 +0000 (UTC)', 'Sun, 10 Aug 2014 
> 02:01:06
>   +0000 (UTC)', 'Sat, 9 Aug 2014 19:41:08 -0700 (PDT)', 'Sat, 9 Aug 2014 
> 22:51:29
>   -0400 (EDT)', 'Sun, 10 Aug 2014 07:34:44 +0200', 'Tue, 5 Aug 2014 
> 01:55:24 +000
> 0 (UTC)']
>  >>> min(date)
> 'Fri, 8 Aug 2014 20:48:44 -0700 (PDT)'
> 
> The result is wrong,the min date should be 'Tue, 5 Aug 2014 01:55:24 +000
> 0 (UTC)' ,how can i get it ?
> 

You neglected to specify your Python version,  but I'll assume at
 least 2.5.

The min function did exactly as it's documented to do, found the
 minimum string, by alphabetical ordering. Since 'F' is less than
 'T' it didn't need to look at the rest.  If you had been sorting
 a list of datetime objects, it would have found the least of
 those. 

Your simplest answer is probably to write a function that converts
 a string like you have into a datetime object, say call it
 converter (). Then after testing it, you call

min (dates, key = converter)

Note I did NOT use parens on converter.

I also used the name dates for the list,  since it's a collection
 of dates. But that assumes you rename it in your code that
 gathered them.

-- 
DaveA

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Re:get the min date from a list Dave Angel <davea@davea.name> - 2014-08-10 07:02 -0400
  Re: get the min date from a list Roy Smith <roy@panix.com> - 2014-08-10 08:46 -0400

csiph-web