Differences and Applications
Differences and Applications
List can be represented Tuple can be represented Set can be Dictionary can be
by by represented by represented by
[ ] ( ) { } { }
List allows Tuple allows Set will not Set will not
duplicate duplicate allow duplicate allow duplicate
elements elements elements elements and
dictionary
doesn’t allow
duplicate keys.
List can use Tuple can use Set can use Dictionary can
nested among all nested among all nested among use nested among
all all
List can be created Tuple can be created Set can be created Dictionary can be
using list() function using tuple() function. using set() function created
using dict() function.
List is mutable i.e we Tuple is immutable i.e Set is mutable i.e we Dictionary is mutable.
can make any changes we can not make any can make any But Keys are not
in list. changes in tuple changes in set. But duplicated.
elements are not
duplicated.
Creating an empty list Creating an empty Tuple Creating a set Creating an empty
dictionary
l=[] t=() a=set()
d={}
b=set(a)
Below is the program for implementation of List, tuple, set, and dictionary:
Python3
# Lists
l = []
# Tuple
t = tuple(l)
# Dictionary
d = {}
Output
Adding 5 and 10 in list [5, 10]
Popped one element from list [5]
Tuple (5,)
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