toby at tobiah.org
Wed Jan 16 20:58:14 CET 2008
Paul Rubin wrote:
> Tobiah <toby at tobiah.org> writes:
>> I tried doing this with a simple example, but noticed
>> that .sort(func) passes two arguments to func, whereas
>> the function expected by groupby() uses only one argument.
> Use: .sort(key=func)
Oh cool. Thanks.
Only in 2.4+ it seems.
>>> a = [1,2,3,4,5]
>>> def sorter(thing):
... return thing % 2 == 0
>>> a.sort(key = sorter)
>>> print a
[1, 3, 5, 2, 4]
Posted via a free Usenet account from http://www.teranews.com
More information about the Python-list