0% found this document useful (0 votes)
2 views2 pages

Python Assignment 3

The document outlines how to perform Create, Read, Update, and Delete (CRUD) operations on Python data structures including lists, tuples, sets, and dictionaries. It also demonstrates the use of list comprehensions for data manipulation. The conclusion emphasizes the efficiency of CRUD operations and the conciseness of list comprehensions in Python.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Python Assignment 3

The document outlines how to perform Create, Read, Update, and Delete (CRUD) operations on Python data structures including lists, tuples, sets, and dictionaries. It also demonstrates the use of list comprehensions for data manipulation. The conclusion emphasizes the efficiency of CRUD operations and the conciseness of list comprehensions in Python.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Assignment 3: Data Structures in Python

Topic: Perform CRUD Operations on Lists, Tuples, Sets,


and Dictionaries, and Use List Comprehensions
Objective:
To perform Create, Read, Update, and Delete (CRUD) operations on Python data
structures and use list comprehensions for data manipulation
1. Lists
# Create
fruits = ["apple", "banana", "cherry"]
# Read
print(fruits[1])
# Update
fruits[1] = "mango"
# Delete
[Link]("apple")
print(fruits)
Output: ['mango', 'cherry']
2. Tuples
# Create
colors = ("red", "green", "blue")
# Read
print(colors[0])
# Tuples are immutable; use conversion to modify
temp = list(colors)
[Link]("yellow")
colors = tuple(temp)
print(colors)
Output: ('red', 'green', 'blue', 'yellow')
3. Sets
# Create
numbers = {1, 2, 3}
# Read
print(2 in numbers)
# Update
[Link](4)
# Delete
[Link](1)
print(numbers)
Output: {2, 3, 4}
4. Dictionaries
# Create
student = {"name": "Aditya", "age": 21}
# Read
print(student["name"])
# Update
student["age"] = 22
# Delete
del student["name"]
print(student)
Output: {'age': 22}
5. List Comprehensions
nums = [1, 2, 3, 4, 5, 6]
squares = [n**2 for n in nums]
evens = [n for n in nums if n % 2 == 0]
print(squares, evens)
Output: [1, 4, 9, 16, 25, 36] [2, 4, 6]
Conclusion:
CRUD operations enable efficient data manipulation in Python structures.

List comprehensions provide a concise way to filter and transform data.

You might also like