[Tutor] Testing Membership in a Sequence

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Mon Mar 15 20:40:03 EST 2004



On Mon, 15 Mar 2004, Danny Yoo wrote:

> The Set class in the 'sets' Standard Library module can make short work
> of this problem:
>
>
> ###
> >>> from sets import Set
> >>> Set(['v', 'b']) & Set(['a', 'b', 'c'])
> >>> Set(['x', 'y']) & Set(['a', 'b', 'c'])
> Set([])
> ###


Argh!  I copied and pasted that wrong.  Let me try that again:


###
>>> from sets import Set
>>> Set(['v', 'b']) & Set(['a', 'b', 'c'])
Set(['b'])
>>> Set(['x', 'y']) & Set(['a', 'b', 'c'])
Set([])
###


Ok, better.  *grin*  My apologies!




More information about the Tutor mailing list