0% found this document useful (0 votes)
7 views3 pages

Python Data Structures Explained

The document provides a Python3 program that demonstrates the use of lists, sets, tuples, and dictionaries. It shows how to add and remove elements from these data structures, highlighting the mutable nature of lists and sets, and the immutability of tuples. Additionally, it illustrates how to manage key-value pairs in dictionaries.

Uploaded by

priya
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views3 pages

Python Data Structures Explained

The document provides a Python3 program that demonstrates the use of lists, sets, tuples, and dictionaries. It shows how to add and remove elements from these data structures, highlighting the mutable nature of lists and sets, and the immutability of tuples. Additionally, it illustrates how to manage key-value pairs in dictionaries.

Uploaded by

priya
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

1.

Programs using elementary data items, lists, dictionaries and tuples

# Python3 program for explaining

# use of list, tuple, set and

# dictionary

# Lists

l = []

# Adding Element into list

[Link](5)

[Link](10)

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

# Popping Elements from list

[Link]()

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

print()

# Set

s = set()

# Adding element into set

[Link](5)

[Link](10)

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


# Removing element from set

[Link](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)

Sample Output:
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'}

You might also like