代码如下:
if order does not matter, you can use
“”.join(set(foo))set() will create a set of unique letters in the string, and “”.join() will join the letters back to a string in arbitrary order.
if order does matter, you can use collections.ordereddict in python 2.7:
from collections import ordereddictfoo = “mppmt”print “”.join(ordereddict.fromkeys(foo))printing
mpt