Search⌘ K
AI Features

Finding the unique items in a sequence

Discover how to find unique items in any sequence using Python sets. Learn to extract unique strings and characters efficiently, which is crucial for solving puzzles and managing data without duplicates.

We'll cover the following...

Sets make it trivial to find the unique items in a sequence.

Python 3.5
a_list = ['The', 'sixth', 'sick', "sheik's", 'sixth', "sheep's", 'sick']
print (set(a_list) ) #①
#{'sixth', 'The', "sheep's", 'sick', "sheik's"}
a_string = 'EAST IS EAST'
print (set(a_string) ) #②
#{'A', 'E', 'S', ' ', 'T', 'I'}
words = ['SEND', 'MORE', 'MONEY']
print (''.join(words)) #③
#SENDMOREMONEY
print (set(''.join(words)) ) #④
#{'R', 'M', 'E', 'S', 'Y', 'O', 'N', 'D'}

① Given a list of several strings, the set() function will return a set of ...