removing duplicates, or, converting Set() to string

maphew at gmail.com maphew at gmail.com
Wed Jul 26 19:35:06 EDT 2006


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




More information about the Python-list mailing list