Hrvoje Niksic wrote:
> "Delaney, Timothy (Tim)" <[EMAIL PROTECTED]> writes:
>
>> Yep - appears I must have been misremembering from another language
>> (dunno which)
>
> Tcl
Not bloody likely - only used Tcl for expect, and then only very
minimally. I'm sure there's at least one language though
ZeD wrote:
> thebjorn wrote:
>
>> int("020")
>>> 20
>> 020
>>> 16
>>
>> You can get the latter behavior using eval:
>
> why using eval when int has the "base" optional parameter?
>
int("020")
> 20
int("020", 8)
> 16
int("09", 8)
> Traceback (most recent call last):
> F
thebjorn wrote:
>> >>> int("020")
>> 20
>> >>> 020
>> 16
>
> You can get the latter behavior using eval:
why using eval when int has the "base" optional parameter?
>>> int("020")
20
>>> int("020", 8)
16
>>> int("09", 8)
Traceback (most recent call last):
File "", line 1, in
ValueError: inval
On Sep 25, 2:45 pm, Steven D'Aprano <[EMAIL PROTECTED]
cybersource.com.au> wrote:
> On Tue, 25 Sep 2007 12:46:54 +0800, Delaney, Timothy (Tim) wrote:
> > Carsten Haese wrote:
>
> >> On Mon, 2007-09-24 at 19:58 +0800, Delaney, Timothy (Tim) wrote:
> >>> I'm sure that in some version of Python it wou
"Delaney, Timothy (Tim)" <[EMAIL PROTECTED]> writes:
> Yep - appears I must have been misremembering from another language
> (dunno which)
Tcl
--
http://mail.python.org/mailman/listinfo/python-list
On Tue, 25 Sep 2007 12:46:54 +0800, Delaney, Timothy (Tim) wrote:
> Carsten Haese wrote:
>
>> On Mon, 2007-09-24 at 19:58 +0800, Delaney, Timothy (Tim) wrote:
>>> I'm sure that in some version of Python it would have given a
>>> ValueError (due to the default radix being 0) but it appears to have
On 9/24/07, Carsten Haese <[EMAIL PROTECTED]> wrote:
> On Mon, 2007-09-24 at 16:53 +0530, Amit Khemka wrote:
> > On 9/24/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> >
> > >>> l = ["1", "11", "2", "22"]
> > >>> sorted(l, cmp = lambda x, y: cmp(int(x), int(y))) # provide your
> > own compare
Carsten Haese wrote:
> On Mon, 2007-09-24 at 19:58 +0800, Delaney, Timothy (Tim) wrote:
>> I'm sure that in some version of Python it would have given a
>> ValueError (due to the default radix being 0) but it appears to have
>> changed to a default radix of 10 somewhere along the way.
>
> Not eve
In article <[EMAIL PROTECTED]>,
[EMAIL PROTECTED] wrote:
> hi,
>
> I have the following list -
>
> ["1", "11", "2", "22"]
>
> how do I sort it like this -
>
> ["1", "2", "11", "22"]
>
> thanks,
>
> aine
Try:
lst.sort(key = lambda s: int(s))
Assuming, of course, that "lst" is your origi
On Mon, 2007-09-24 at 19:58 +0800, Delaney, Timothy (Tim) wrote:
> I'm sure that in some version of Python it would have given a
> ValueError (due to the default radix being 0) but it appears to have
> changed to a default radix of 10 somewhere along the way.
Not even Python 1.5.2 seems to have a
aine_canby wrote:
> I have the following list -
>
> ["1", "11", "2", "22"]
>
> how do I sort it like this -
>
> ["1", "2", "11", "22"]
>>> items = ["1", "11", "2", "22"]
>>> items.sort(key=int)
>>> items
['1', '2', '11', '22']
This is more efficient than Amit's compare function and even Bruno
Carsten Haese wrote:
> That interpreter session is a work of fiction, since sorted returns
> the sorted list instead of sorting the list in place. Also, it's
> better (i.e. more readable and likely faster) to use a sort key
> function instead of a comparison function whenever possible. In this
> c
On Mon, 2007-09-24 at 16:53 +0530, Amit Khemka wrote:
> On 9/24/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> > hi,
> >
> > I have the following list -
> >
> > ["1", "11", "2", "22"]
> >
> > how do I sort it like this -
> >
> > ["1", "2", "11", "22"]
> >
>
> Hi,
>
> >>> l = ["1", "11", "2",
[EMAIL PROTECTED] a écrit :
> hi,
>
> I have the following list -
>
> ["1", "11", "2", "22"]
>
> how do I sort it like this -
>
> ["1", "2", "11", "22"]
source = ["1", "11", "2", "22"]
result = [t[1] for t in sorted((int(item), item) for item in source)]
print result
--
http://mail.python.or
On 9/24/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> hi,
>
> I have the following list -
>
> ["1", "11", "2", "22"]
>
> how do I sort it like this -
>
> ["1", "2", "11", "22"]
>
Hi,
>>> l = ["1", "11", "2", "22"]
>>> sorted(l, cmp = lambda x, y: cmp(int(x), int(y))) # provide your
own comp
hi,
I have the following list -
["1", "11", "2", "22"]
how do I sort it like this -
["1", "2", "11", "22"]
thanks,
aine
--
http://mail.python.org/mailman/listinfo/python-list
16 matches
Mail list logo