mk <mrk...@gmail.com> writes: > Hello everyone, > > I have two lists of IP addresses: > > hostips = [ 'a', 'b', 'c', 'd', 'e' ] > > thread_results = [ 'd', 'b', 'c' ] > > I need to sort thread_results in the same order as hostips.
[...solution:] > hostips_limited = [] > for h in hostips: > if h in thread_results: > hostips_limited.append(h) > > ..and then doing sorting thread_results. What do you mean by that last sentence? [... or:] > Incidentally, it *seems* that list comprehension preserves order: > > hostips_limited = [ h for h in hostips if h in thread_results ] That's ok, but why not keep thread_results as a set instead of a list if the ordering in that container is not significant but you are testing membership a lot? -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list