Remove duplicate letters in a word
Roman Suzi
rnd at onego.ru
Sun Jun 22 14:46:31 EDT 2003
One more interesting method to do the same:
import sets
def nodups2(s):
l = map(lambda x: (s.index(x[1]),x[0]), enumerate(sets.Set(s)))
l.sort()
return "".join(map(lambda x: s[x[0]], l))
print nodups2('secret')
This implementation uses the fact that index gives the first
encounter of a symbol in a string.
Sincerely yours, Roman Suzi
--
rnd at onego.ru =\= My AI powered by GNU/Linux RedHat 7.3
More information about the Python-list
mailing list