[EMAIL PROTECTED] wrote: > Hello, > > I have some lists for which I need to remove duplicates. I found the > sets.Sets() module which does exactly this, but how do I get the set > back out again? > > # existing input: A,B,B,C,D > # desired result: A,B,C,D > > import sets > dupes = ['A','B','B','C','D'] > clean = sets.Set(dupes) > > out = open('clean-list.txt','w') > out.write(clean) > out.close > > --- > out.write(clean) fails with "TypeError: argument 1 must be string or > read-only character buffer, not Set" and out.write( str(clean) ) > creates "Set(['A', 'C', 'B', 'D'])" instead of just A,B,C,D. > > thanks in advance for your time, > > -matt
Do ','.join(clean) to make a single string with commas between the items in the set. (If the items aren't all strings, you'll need to convert them to strings first.) Peace, ~Simon -- http://mail.python.org/mailman/listinfo/python-list