beginner, idiomatic python

bambam david at asdf.asdf
Fri Aug 24 01:20:04 EDT 2007


Excellent. By symmetry, I see that "list" casts the set back into a list.

I wonder why list has not been extended with the same (difference,
interesection) methods?  Casting to set looks a little kludgy:

c = list(set(a)-set(b))

I wonder if that is clearer than the explicit loop?

Steve.

"Gabriel Genellina" <gagsl-py2 at yahoo.com.ar> wrote in message 
news:mailman.230.1187928865.32294.python-list at python.org...
> En Thu, 23 Aug 2007 23:54:14 -0300, bambam <david at asdf.asdf> escribi?:
>
>> After examining your suggestion, I realised that another thing
>> I am interested in could be generalised: I want the complement
>> of the set of ports in pages, given a universal set in tempList.
>> Ignoring the break condition for the moment, and my problem
>> with int(port)/str(port), would you have offered a different solution
>> if I had asked for the relative complement of a small set?
>>
>> a= ['a','b','c']
>> b= ['b']
>> c= a-b #set theoretic difference, a\b, a.~b, ['a','c']
>
> If you want a set - just use a set:
>
> py> a = set(['a','b','c'])
> py> b = set(['b'])
> py> c = a-b
> py> c
> set(['a', 'c'])
>
> -- 
> Gabriel Genellina
> 





More information about the Python-list mailing list