Interesting (?) problem
__peter__ at web.de
Mon Jan 11 19:34:51 CET 2010
> mk wrote:
>> 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.
> P.S. One clarification: those lists are actually more complicated
> (thread_result is a list of tuples (ip, thread)), which is why I need
> thread_results sorted in order of hostips (instead of just constructing
> [ h for h in hostips if h in thread_results ] and be done with it).
[(host, thread) for host, thread in thread_results if host in hostips]
then. However, if you care to explain what you're intending to do with the
resulting list I'm sure someone will come up with a more efficient approach
based on sets or dicts.
More information about the Python-list