bryanvick at gmail.com
Wed Apr 29 18:43:10 CEST 2009
On Apr 28, 11:16 pm, Arnaud Delobelle <arno... at googlemail.com> wrote:
> Kay Schluehr <kay.schlu... at gmx.net> writes:
> > On 29 Apr., 05:41, Ross <ross.j... at gmail.com> wrote:
> >> If I have a list x = [1,2,3,4,5,6,7,8,9] and another list that is a
> >> subset of x: y = [1,4,7] , is there a quick way that I could return
> >> the complementary subset to y.... z=[2,3,5,6,8,9] ?
> >> The reason I ask is because I have a generator function that generates
> >> a list of tuples and I would like to divide this list into
> >> complementary lists.
> > z = [u for u in x if u not in y]
> > or
> > z = [u for u in x if u not in set(y)]
> The above will evaluate set(y) for each element in x.
> s = set(y)
> z = [u for u in x if u not in s]
>>>ls = [1, 2, 3, 4, 5]
>>>s = set(ls)
['your are handsome', 'your are smart', 'nice jacket'
More information about the Python-list