[Tutor] Arbitrary-argument set function
Dave Angel
davea at davea.name
Wed Oct 2 01:00:00 CEST 2013
On 1/10/2013 18:43, Spyros Charonis wrote:
> Dear Pythoners,
>
>
> I am trying to extract from a set of about 20 sequences, the characters
> which are unique to each sequence. For simplicity, imagine I have only 3
> "sequences" (words in this example) such as:
>
>
> s1='spam'; s2='scam', s3='slam'
>
>
> I would like the character that is unique to each sequence, i.e. I need my
> function to return the list [ 'p', 'c', ',l' ]. This function I am using is
> as follows:
>
Suggest you turn each sequence into a set, and use set difference to
find all the characters that aren't in any other set.
So you make a list of such sets (perhaps 20 items in the list). Now
just loop through the sets, subtracting from each one all the others.
Simple double-nested loop.
--
DaveA
More information about the Tutor
mailing list