[Tutor] sets module equivalent with Python 2.6

bob gailer bgailer at gmail.com
Sat Apr 11 03:40:13 CEST 2009


PyProg PyProg wrote:
> Hello all,
>
> I want to use an equivalent of sets module with Python 2.6 ... but
> sets module is deprecated on 2.6 version.
>   

set is now a built-in type.
Replace sets.Set() with set()

> In fact I want to make that but with Python 2.6:
>
>   
>>>> toto_1 = [0, 1, 2, 3, 4]
>>>> toto_2 = [1, 127, 4, 7, 12]
>>>>
>>>> import sets
>>>> a = sets.Set(toto_1)
>>>> b = sets.Set(toto_2)
>>>> c = a.symmetric_difference(b)
>>>> d = [p for p in c]
>>>> d.sort()
>>>> print d
>>>>         

Note [p for p in c] can be simplified to list(c)

> [0, 2, 3, 7, 12, 127]
>
> Can you help me ?.
>   

Looks like we did.
> Thanks in advance.
>   

Welcome in retrospect.

-- 
Bob Gailer
Chapel Hill NC
919-636-4239


More information about the Tutor mailing list