Dick Moores wrote:
> At 09:53 PM 12/6/2006, Luke Paireepinart wrote:
>> # Remove duplicates from a list:
>> >>> L = [1,2,2,3,3,3]
>> >>> [x for x in L if x not in locals()['_[1]'].__self__]
>> [1,2,3]
>
> Why not
> >>> L = [1,2,2,3,3,3]
> >>> list(set(L))
> [1, 2, 3]
Because the other methods (via set or dict keys) don't preserve order, 
and the list comprehension version does.
The others may have preserved order in this case, but won't always.
-Luke
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to