Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

How to Use Sets to Remove Duplicate Items in Other Data Structures

# We can use sets to get rid of duplicate items in other data structures like lists and tuples.

numberList = [2, 2, 4, 8, 9, 10, 8, 2, 5, 7, 3, 4, 7, 9]

numberSet = set(numberList)

print(numberSet)
# {2, 3, 4, 5, 7, 8, 9, 10}

# This is useful when you are dealing with a very large data
# set that requires only the individual unit of items returned
# instead of the number of occurrences of the items.
Source by www.freecodecamp.org #
 
PREVIOUS NEXT
Tagged: #How #Use #Sets #Remove #Duplicate #Items #Other #Data #Structures
ADD COMMENT
Topic
Name
5+4 =