Page List

Monday, April 30, 2012

Find unique characters in a string

An example of finding unique characters in a string using set and re

testStr = 'AAA 7 BBBB C 1 DDD d Y ZZ 3'
''.join( set(re.findall(r'[a-zA-Z]',testStr)) )
Output:
'ACBDYZd'