Scott David Daniels wrote:
>> map(tuple,map(reversed,list(enumerate(a
>
> Doesn't the following read more easily?
>
> [tuple(reversed(x)) for x in enumerate(a)]
that involves two extra name lookups for each item in the sequence,
though, so it doesn't execute more easily.
--
http:/
Paul McGuire wrote:
> In the interests of beating a dead horse into the ground
>(metaphor-mixing?),
> I looked at using map to one-line the OP's request, and found an interesting
> inconsistency.
>
> I tried using map(reversed, list(enumerate(a))), but got back a list of
> iterators. To c
Paul Rubin wrote:
> Gabriel Genellina <[EMAIL PROTECTED]> writes:
>
>>> >>> sorted((x[1], x[0]) for x in enumerate(a))
>>>[(1, 7), (2, 4), (2, 8), (3, 2), (4, 1), (5, 3), (6, 5), (7, 6), (9, 0)]
>>
>>Why forcing to use enumerate if it doesn't fit? And a generator won't
>>help here since you have
Paul McGuire wrote:
> "Steve Holden" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
>
>
> >>> [x for x in enumerate(a)]
> [(0, 9), (1, 4), (2, 3), (3, 5), (4, 2), (5, 6), (6, 7), (7, 1), (8, 2)]
>
>
> Just curious, Steve, but why do this list comprehension when:
>
> list(enum
Gabriel Genellina <[EMAIL PROTECTED]> writes:
> > >>> sorted((x[1], x[0]) for x in enumerate(a))
> >[(1, 7), (2, 4), (2, 8), (3, 2), (4, 1), (5, 3), (6, 5), (7, 6), (9, 0)]
>
> Why forcing to use enumerate if it doesn't fit? And a generator won't
> help here since you have to access all the item
At Wednesday 27/9/2006 08:51, Steve Holden wrote:
If you want the indexes as well you need to become a bit tricky.
Remember that enumerate() will produced two-element tuples with the
index value associated with the list value.
>>> [x for x in enumerate(a)]
[(0, 9), (1, 4), (2, 3), (3, 5), (4,
"Steve Holden" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
>>> [x for x in enumerate(a)]
[(0, 9), (1, 4), (2, 3), (3, 5), (4, 2), (5, 6), (6, 7), (7, 1), (8, 2)]
Just curious, Steve, but why do this list comprehension when:
list(enumerate(a))
works just as well?
In the in
Satya Upadhya wrote:
> Dear Friends,
> I am having a few issues with respect to sorting using python. I am using
> Python 2.4.3 Win32 (IDLE 1.1.3).
>
x = [2,6,4]
x.sort()
x
> [2, 4, 6]
x = [2,6,4]
y = []
y = x.sort()
y
print y
> None
>
> So the problem esse
Dear Friends,I am having a few issues with respect to sorting using python. I am usingPython 2.4.3 Win32 (IDLE 1.1.3).>>> x = [2,6,4]>>> x.sort()>>> x[2, 4, 6]>>> x = [2,6,4]>>> y = []>>> y = x.sort()>>> y>>> print yNoneSo the problem essentially is that i am unable to store the sortedelements of l