Python - Store Unique Values
Last Updated: 1649Z 23SEP19
(Created: 1649Z 23SEP19)
Use sets to store uniqiue values.
Signatures:
None
Examples:
import random
all_words = "all the words in the world".split()
def get_random_word():
return random.choice(all_words)
def get_unique_words():
words = set()
for _ in range(1000):
words.add(get_random_word())
return words
print(get_unique_words()) # output: {'world', 'all', 'the', 'words'}
References: