Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
3 views

Python ListSetTuple Dict

The document provides an overview of four data structures in Python: lists, tuples, sets, and dictionaries, highlighting their characteristics, representation, and mutability. Lists and dictionaries are mutable and allow duplicates, while tuples are immutable and sets do not allow duplicates. Examples of creating and manipulating each data structure are included, demonstrating their usage in Python code.

Uploaded by

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

Python ListSetTuple Dict

The document provides an overview of four data structures in Python: lists, tuples, sets, and dictionaries, highlighting their characteristics, representation, and mutability. Lists and dictionaries are mutable and allow duplicates, while tuples are immutable and sets do not allow duplicates. Examples of creating and manipulating each data structure are included, demonstrating their usage in Python code.

Uploaded by

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

List Tuple Set Dictionary

A list is a non- A Tuple is also a non- The set data


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

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

The Set will not The dictionary


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

The dictionary can


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

Example: {1: “a”, 2:


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

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

A set is mutable i.e


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

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

Creating an empty Creating an empty Creating a set Creating an empty


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

# 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
s = set()

# Adding element into set


s.add(5)
s.add(10)
print("Adding 5 and 10 in set", s)

# Removing element from set


s.remove(5)
print("Removing 5 from set", s)
print()

# Tuple
t = tuple(l)

# Tuples are immutable


print("Tuple", t)
print()

# Dictionary
d = {}

# Adding the key value pair


d[5] = "Five"
d[10] = "Ten"
print("Dictionary", d)

# Removing key-value pair


del d[10]
print("Dictionary", d)

You might also like