> > > 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, > e.g. > > 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:)
-- http://mail.python.org/mailman/listinfo/python-list