sorting two corresponding lists?
icebergwtf at gmail.com
Fri Apr 24 19:11:05 CEST 2009
> > 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
> [items[values.index(i)] for i in new_values]
All these variances prove how python amazing is, thanks!
> (Although 'i' is not a good choice of variable as it represents a
> value, not an index)
Actually, I think 'i' indeed represents index of each sorted values in
original values list
> Anyway it doesn't work well if the 'values' list has repeated values,
> items = ['spam', 'eggs', 'wafer']
> values = [3, 7, 3]
Yes, I didn't even think about this situation!
I'm new to python too, as original poster Esmail, there are a lot of things
to learn to be a real pythoner:)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-list