On Apr 24, 2:32 am, Hans DushanthaKumar
hans.dushanthaku...@hcn.com.au 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
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
Saketh saketh.bhamidip...@gmail.com (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
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(new_values)
+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:)
items = ['apple', 'car', 'town
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]
I would like to sort the 'items
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
://0047/!x-usc:mailto:ebo...@hotmail.com
To:
python-list@python.orgmhtml:{154E1F55-D942-4CE9-9B8C-82060E1E80CE}mid://0047/!x-usc:mailto:python-list@python.org
Sent: Tuesday, April 21, 2009 12:10 AM
Subject: sorting two corresponding lists?
Hello all,
I wonder if someone could help me
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 the 'zip' version is
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)
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' list based
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 = [5, 2, 7, 1]
I would like to sort
On Apr 20, 12:10 pm, Esmail ebo...@hotmail.com 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
Quoting Esmail ebo...@hotmail.com:
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:
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 =
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
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
Esmail ebo...@hotmail.com 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 = [5, 2, 7, 1]
I
18 matches
Mail list logo