>
> > Just being pedantic here :)
> >
> > [items[x] for x in [i for i in map(values.index, new_values)]]
> >
> > Is the same as
> >
> > [items[x] for x in map(values.index, new_values)]
>
> It's also the same as
>
>[items[x] for x in [values.index(i) for i in new_values]]
>
> Which reduces to
>
On Apr 24, 2:32 am, "Hans DushanthaKumar"
wrote:
> Just being pedantic here :)
>
> [items[x] for x in [i for i in map(values.index, new_values)]]
>
> Is the same as
>
> [items[x] for x in map(values.index, new_values)]
It's also the same as
[items[x] for x in [values.index(i) for i in new_va
+hans.dushanthakumar=hcn.com...@python.org]
On Behalf Of Esmail
Sent: Friday, 24 April 2009 3:02 AM
To: tiefeng wu
Cc: python-list@python.org
Subject: Re: sorting two corresponding lists?
> My solution, I know the 'zip' version is more elegant, this is just
for
> fun:)
>
> >>>
My solution, I know the 'zip' version is more elegant, this is just for
fun:)
>>> items = ['apple', 'car', 'town', 'phone']
>>> values = [5, 2, 7, 1]
>>> new_values = sorted(values, reverse = True)
>>> new_items = [items[x] for x in [i for i in map(values.index,
new_values)]]
>>> print
> Saketh (S) wrote:
>S> Why not use a dictionary instead of two lists? Then you can sort the
>S> dictionary by value -- e.g.
>S> d = dict(zip(items, values))
>S> sorted_items = sorted(d.iteritems(), key=lambda (k,v): (v,k))
>S> This produces a list of pairs, but demonstrates the general ide
>From http://wiki.python.org/moin/HowTo/Sorting#Sortingbykeys, using the
>Decorate-Sort-Undecorate (aka Schwartzian transform) idiom:
#!/usr/bin/env python
items = ['apple', 'car', 'town', 'phone']
values = [5, 2, 7, 1]
zipped=zip(values,items)
zipped.sort(reverse=True)
values_sorted,items_sorte
>
> Esmail wrote:
>
> > items = [apple, car, town, phone]
> > values = [5, 2, 7, 1]
> >
> > I would like to sort the 'items' list based on the 'values' list so
> > that I end up with the following two list:
> >
> > items = [town, apple, car, phone]
> > values = [7, 5, 2, 1]
My solution, I know th
0 AM
Subject: sorting two corresponding lists?
> Hello all,
>
> I wonder if someone could help me with sorting two corresponding lists.
>
> For instance the first list contains some items, and the second list
> contains their value (higher is better)
>
> items = [apple, car,
Esmail wrote:
items = [apple, car, town, phone]
values = [5, 2, 7, 1]
I would like to sort the 'items' list based on the 'values' list so
that I end up with the following two list:
items = [town, apple, car, phone]
values = [7, 5, 2, 1]
Hello all,
thanks for all the great suggestions. I use
Esmail wrote:
> I wonder if someone could help me with sorting two corresponding lists.
>
> For instance the first list contains some items, and the second list
> contains their value (higher is better)
>
> items = [apple, car, town, phone]
> values = [5, 2, 7, 1]
>
&g
Esmail writes:
> Hello all,
>
> I wonder if someone could help me with sorting two corresponding lists.
>
> For instance the first list contains some items, and the second list
> contains their value (higher is better)
>
> items = [apple, car, town, phone]
> values
Thanks Luis, more code for me to study and learn from.
Esmail
Luis Alberto Zarrabeitia Gomez wrote:
I've used this sometimes:
--
http://mail.python.org/mailman/listinfo/python-list
Saketh wrote:
Why not use a dictionary instead of two lists? Then you can sort the
dictionary by value -- e.g.
thanks for the suggestion. I am not sure this is quite suitable for my
application (the example I provided was extremely simplified), but this
is a useful technique to know and has b
Hi Diez,
Thanks for this, I had seen zip() before but had no idea
really what it does, this will serve as good motivation to
find out more.
I'm amazed at what this language can do (and the helpfulness
of the people on the list here).
Best,
Esmail
Diez B. Roggisch wrote:
items = zip(*sorted(z
Quoting Esmail :
> items = [apple, car, town, phone]
> values = [5, 2, 7, 1]
>
> I would like to sort the 'items' list based on the 'values' list so
> that I end up with the following two list:
>
> items = [town, apple, car, phone]
> values = [7, 5, 2, 1]
I've used this sometimes:
=== [unte
On Apr 20, 12:10 pm, Esmail wrote:
> Hello all,
>
> I wonder if someone could help me with sorting two corresponding lists.
>
> For instance the first list contains some items, and the second list
> contains their value (higher is better)
>
> items = [apple, car, town, ph
Esmail wrote:
> Hello all,
>
> I wonder if someone could help me with sorting two corresponding lists.
>
> For instance the first list contains some items, and the second list
> contains their value (higher is better)
>
> items = [apple, car, town, phone]
> values
Hello all,
I wonder if someone could help me with sorting two corresponding lists.
For instance the first list contains some items, and the second list
contains their value (higher is better)
items = [apple, car, town, phone]
values = [5, 2, 7, 1]
I would like to sort the 'items'
18 matches
Mail list logo