Remove duplicate letters in a word

Roman Suzi rnd at
Sun Jun 22 20:46:31 CEST 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)))
  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 =\= My AI powered by GNU/Linux RedHat 7.3

More information about the Python-list mailing list