Finding the unique items in a sequence
We'll cover the following...
Sets make it trivial to find the unique items in a sequence.
Press + to interact
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)) #③#SENDMOREMONEYprint (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 ...