complementary lists?

Paul Rubin http
Wed Apr 29 01:05:57 EDT 2009


Ross <ross.jett at gmail.com> writes:
> 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] ?

    >>> x = [1,2,3,4,5,6,7,8,9]
    >>> y = [1,4,7]
    >>> print sorted(set(x)-set(y))
    [2, 3, 5, 6, 8, 9]



More information about the Python-list mailing list