[Tutor] Arbitrary-argument set function
Spyros Charonis
s.charonis at gmail.com
Wed Oct 2 00:43:09 CEST 2013
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:
def uniq(*args):
""" FIND UNIQUE ELEMENTS OF AN ARBITRARY NUMBER OF SEQUENCES"""
unique = []
for i in args[0]:
if i not in args[1:]:
unique.append(i)
return unique
and is returning the list [ 's', 'p', 'a', 'm' ]. Any help much appreciated,
Best,
Spyros
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20131001/8e410c12/attachment.html>
More information about the Tutor
mailing list