A set is a good way to handle this:
>>> a = ['google.com', 'livejournal.com', 'livejournal.com', 'google.com', 'stackoverflow.com'] >>> b = set(a) >>> b set(['livejournal.com', 'google.com', 'stackoverflow.com']) >>>
One of the w / r / t suggestions is the first answer: that sets and dicts better extract unique results quickly, list memberships are O (n) compared to O (1) for other types, so if you want to store additional data or doing something like creating the specified unique_results list, it might be better to do something like:
unique_results = {} >>> for item in a: unique_results[item] = '' >>> unique_results {'livejournal.com': '', 'google.com': '', 'stackoverflow.com': ''}
unmounted
source share