Differences and Applications of List, Tuple, Set and Dictionary in Python

30 Jan, 2022
Lists: are just like dynamic sized arrays, declared in other languages (vector in C++ and ArrayList in Java). Lists need not be homogeneous always which makes it the most powerful tool in Python.
Tuple: A Tuple is a collection of Python objects separated by commas. In some ways, a tuple is similar to a list in terms of indexing, nested objects, and repetition but a tuple is immutable, unlike lists that are mutable.
Set: A Set is an unordered collection data type that is iterable, mutable, and has no duplicate elements. Python’s set class represents the mathematical notion of a set.
Dictionary: in Python is an ordered (since Py 3.7) [unordered (Py 3.6 & prior)] collection of data values, used to store data values like a map, which, unlike other Data Types that hold only a single value as an element, Dictionary holds key:value pair. Key-value is provided in the dictionary to make it more optimized.
List, Tuple, Set, and Dictionary are the data structures in python that are used to store and organize the data in an efficient manner.
Tuple can be represented by  
( )
Creating an empty list
l=[]
Creating an empty Tuple
t=()
Creating a set
a=set()
b=set(a)
Creating an empty dictionary
d={}
Below is the program for implementation of List, tuple, set, and dictionary:
Python3
# Python3 program for explaining# use of list, tuple, set and# dictionary # Listsl = [] # Adding Element into listl.append(5)l.append(10)print("Adding 5 and 10 in list", l) # Popping Elements from listl.pop()print("Popped one element from list", l)print() # Sets = set() # Adding element into sets.add(5)s.add(10)print("Adding 5 and 10 in set", s) # Removing element from sets.remove(5)print("Removing 5 from set", s)print() # Tuplet = tuple(l) # Tuples are immutableprint("Tuple", t)print() # Dictionaryd = {} # Adding the key value paird[5] = "Five"d[10] = "Ten"print("Dictionary", d) # Removing key-value pairdel d[10]print("Dictionary", d)
Adding 5 and 10 in list [5, 10]
Popped one element from list [5]

Adding 5 and 10 in set {10, 5}
Removing 5 from set {10}

Tuple (5,)

Dictionary {5: 'Five', 10: 'Ten'}
Dictionary {5: 'Five'}
List:
Used in JSON format
Useful for Array operations
Used in Databases
Tuple:
Used to insert records in the database through SQL query at a time.Ex: (1.’sravan’, 34).(2.’geek’, 35)
Used in parentheses checker
Set:
Finding unique elements
Join operations
Dictionary:
Used to create a data frame with lists
Used in JSON
surinderdawra388
w0hm0xnhdyk12cu4wsge4penk19t9nyan6aem2nc
Python dictionary-programs
python-list
python-set
python-tuple
Articles
Data Structures
Difference Between
Python
Python Programs
Data Structures
python-list
python-set
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Must Do Questions for Companies like TCS, CTS, HCL, IBM ...
Const keyword in C++
Service-Oriented Architecture
Advantages and Disadvantages of Linked List
What's the difference between Scripting and Programming Languages?
DSA Sheet by Love Babbar
SDE SHEET - A Complete Guide for SDE Preparation
Top 50 Array Coding Problems for Interviews
Introduction to Data Structures
Doubly Linked List | Set 1 (Introduction and Insertion)