Search
 
SCRIPT & CODE EXAMPLE
 

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.
Comment

PREVIOUS NEXT
Code Example
Python :: rmtree (remove tree) example 
Python :: How determine if a number is even or odd using Recursive Inner Function 
Python :: Creating a Tuple with Mixed Datatypes. 
Python :: find downold dir in python 
Python :: Count the number of Non-Missing Values in the DataFrame 
Python :: import * with __import__ 
Python :: multiple ternary operator python 
Python :: how to scale numbers between -1 and 1 python 
Python :: remot mouce use python 
Python :: A Python program to demonstrate inheritance 
Python :: python Prefix Sum of Matrix (Or 2D Array) 
Python :: pygame lerp 
Python :: python yellow 
Python :: gensim loop through models 
Python :: how to clear formatting in python 
Python :: how to set notepad ++ for run python 
Python :: dynamic list in python 
Python :: how to give tab space in python 
Python :: Boolean comparison w/out if statements 
Python :: increase tkinter window resolution 
Python :: python Access both key and value using iteritems() Return keys or values explicitly 
Python :: python array to text 
Python :: nums: List[int] in python function 
Python :: western school district 
Python :: how to write statements in python 
Python :: pandas map 
Python :: python messaging networking 
Python :: all possibilities of 0 and 1 
Python :: Access the Response Methods and Attributes in python Show redirections 
Python :: flask logging miguel grinberg 
ADD CONTENT
Topic
Content
Source link
Name
6+1 =