0% found this document useful (0 votes)
148 views

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

Uploaded by

Dinesh kumaran
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
148 views

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

Uploaded by

Dinesh kumaran
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

List Tuple Set Dictionary

A list is a non- The set data


A Tuple is also a
homogeneous structure is also a A dictionary is
non-homogeneous
data structure that non- also a non-
data structure that
stores the homogeneous homogeneous
stores elements in
elements in data structure but data structure
columns of a
columns of a stores the that stores key-
single row or
single row or elements in a value pairs.
multiple rows.
multiple rows. single row.

The dictionary
The list can be Tuple can be The set can be can be
represented by [ ] represented by ( ) represented by { } represented by {
}

The Set will not The dictionary


The list allows Tuple allows
allow duplicate doesn’t allow
duplicate elements duplicate elements
elements duplicate keys.

The dictionary
The list can use Tuple can use The set can use
can use nested
nested among all nested among all nested among all
among all

Example: {1: “a”,


Example: [1, 2, 3, Example: (1, 2, 3, Example: {1, 2, 3,
2: “b”, 3: “c”, 4:
4, 5] 4, 5) 4, 5}
“d”, 5: “e”}

A setA dictionary A dictionary can


A list can be Tuple can be
can be created be created using
created using the created using the
using the set() the dict()
list() function tuple() function.
function function.

We use cookies to ensure you have the best browsing experience on our website. By using
our site, you acknowledge that you have read and understood our Cookie Policy & Privacy
Policy
List Tuple Set Dictionary

A tuple is A set is mutable


A dictionary is
A list is mutable i.e immutable i.e we i.e we can make
mutable, ut Keys
we can make any can not make any any changes in the
are not
changes in the list. changes in the set, ut elements
duplicated.
tuple. are not duplicated.

Dictionary is
List is ordered Tuple is ordered Set is unordered ordered (Python
3.7 and above)

Creating an empty Creating an empty Creating a set Creating an


list Tuple empty dictionary
a=set()
l=[] t=() b=set(a) d={}

Below is the program for the implementation of list, tuple, set, and
dictionary:

Python3

# Python3 program for explaining


# use of list, tuple, set and
# dictionary

# Lists
l = []

# Adding Element into list


l.append(5)
l.append(10)
print("Adding 5 and 10 in list", l)

# Popping Elements from list


l.pop()
print("Popped one element from list", l)
print()

# Set
We uses cookies
= set()to ensure you have the best browsing experience on our website. By using
our site, you acknowledge that you have read and understood our Cookie Policy & Privacy
# Adding element into set Policy
s.add(5)

You might also like