On Thu, Jan 14, 2010 at 10:13 AM, Stefan Behnel wrote:
>
> Note that this won't work in Py3, where the "cmp" parameter is gone.
>
> Stefan
And he's right again. I should've checked for that. Well, that makes a
CmpInt class the only other solution:
class CmpInt(int):
def __lt__(self, other):
Lie Ryan, 14.01.2010 01:47:
On 01/14/10 06:56, Hugo Arts wrote:
On Wed, Jan 13, 2010 at 8:21 PM, Stefan Behnel wrote:
Hugo Arts, 13.01.2010 15:25:
Here is my solution for the general case:
from itertools import groupby
def alphanum_key(string):
t = []
for isdigit, group in groupby(stri
On Thu, Jan 14, 2010 at 1:47 AM, Lie Ryan wrote:
> On 01/14/10 06:56, Hugo Arts wrote:
>> On Wed, Jan 13, 2010 at 8:21 PM, Stefan Behnel wrote:
>>> Hugo Arts, 13.01.2010 15:25:
Here is my solution for the general case:
from itertools import groupby
def alphanum_key(string
On 01/14/10 06:56, Hugo Arts wrote:
> On Wed, Jan 13, 2010 at 8:21 PM, Stefan Behnel wrote:
>> Hugo Arts, 13.01.2010 15:25:
>>>
>>> Here is my solution for the general case:
>>>
>>> from itertools import groupby
>>> def alphanum_key(string):
>>>t = []
>>>for isdigit, group in groupby(strin
On Wed, Jan 13, 2010 at 2:21 PM, Stefan Behnel wrote:
> Hugo Arts, 13.01.2010 15:25:
>>
>> Here is my solution for the general case:
>>
>> from itertools import groupby
>> def alphanum_key(string):
>> t = []
>> for isdigit, group in groupby(string, str.isdigit):
>> group = ''.join(gro
On Wed, Jan 13, 2010 at 8:21 PM, Stefan Behnel wrote:
> Hugo Arts, 13.01.2010 15:25:
>>
>> Here is my solution for the general case:
>>
>> from itertools import groupby
>> def alphanum_key(string):
>> t = []
>> for isdigit, group in groupby(string, str.isdigit):
>> group = ''.join(gro
Hugo Arts, 13.01.2010 15:25:
Here is my solution for the general case:
from itertools import groupby
def alphanum_key(string):
t = []
for isdigit, group in groupby(string, str.isdigit):
group = ''.join(group)
t.append(int(group) if isdigit else group)
return t
Note
fore 'a2'.
now with alphanumeric sort:
>>> a.sort(key=alphanum_key)
>>> a
['0a', '1a', '10a', 'a1', 'a2', 'a10', 'a11', 'b2', 'b3', 'b20']
Hugo
On Wed, Jan 13, 2010 at 2:
Wed, 1/13/10, Sander Sweers wrote:
From: Sander Sweers
Subject: Re: [Tutor] samples on sort method of sequence object.
To: "Albert-Jan Roskam"
Cc: "*tutor python"
Date: Wednesday, January 13, 2010, 2:14 PM
2010/1/13 Albert-Jan Roskam
>
> Interesting. Can this also
2010/1/13 Albert-Jan Roskam
>
> Interesting. Can this also be used to make sorting of alphanumerical list
> items in a 'numerical' way easier?
> >>> x
> ['var_0', 'var_13', 'var_11', 'var_9', 'var_4', 'var_1', 'var_5', 'var_6',
> 'var_7', 'var_14', 'var_2', 'var_3', 'var_8', 'var_10', 'var_12']
Albert-Jan Roskam, 13.01.2010 13:51:
Interesting. Can this also be used to make sorting of alphanumerical list items
in a 'numerical' way easier? E.g.:
x
['var_0', 'var_13', 'var_11', 'var_9', 'var_4', 'var_1', 'var_5', 'var_6',
'var_7', 'var_14', 'var_2', 'var_3', 'var_8', 'var_10', 'var_12'
are zfilled versions of the list items (e.g.
var_01, etc), then sort the keys, get the dictionary values in the right order,
etc. It seemed a cumbersome way. Isn't there an easier way to sort x?
Cheers!!
Albert-Jan
~~
In the face of am
On Tue, Jan 12, 2010 at 9:39 AM, Make Twilight wrote:
> I can understand how to use parameters of cmp and reverse,except the
> key parameter...
> Would anyone give me an example of using sort method with key parameter?
http://personalpages.tds.net/~kent37/kk/7.html
Kent
___
On Tue, Jan 12, 2010 at 3:39 PM, Make Twilight wrote:
> Hi,there:
> The document of
> Python.org[http://docs.python.org/library/stdtypes.html] says that:
>
>
>
> I can understand how to use parameters of cmp and reverse,except the
> key parameter...
> Would anyone give me an example of using s
Hi,there:
The document of
Python.org[http://docs.python.org/library/stdtypes.html] says that:
--
s.sort([cmp[, key[, reverse]]])
8. The sort() method takes optional arguments fo
15 matches
Mail list logo