remove a list from a list

Tim Chase python.list at tim.thechases.com
Fri Nov 17 14:48:27 EST 2006


> from sets import Set as set   # Python 2.3
> 
> b = list( set([i.upper() for i in b) - set([i.upper() for i in a] ) )

Just a caveat...this can change the order of items in the results 
as sets (and their differences) are inherently unordered data 
structures.  If order of the items in the list need to preserved, 
it must remain as a list.  However, if the order of the resulting 
list doesn't matter, this is a good solution.

-tkc






More information about the Python-list mailing list