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

Python 1

The document contains multiple code snippets demonstrating various operations on data structures in Python, including tuples, lists, and dictionaries. Key operations include finding indices, counting elements, appending, removing, reversing lists, and updating dictionary values. Each code snippet is followed by its expected output, showcasing the results of the operations performed.

Uploaded by

magarratna471
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)
15 views3 pages

Python 1

The document contains multiple code snippets demonstrating various operations on data structures in Python, including tuples, lists, and dictionaries. Key operations include finding indices, counting elements, appending, removing, reversing lists, and updating dictionary values. Each code snippet is followed by its expected output, showcasing the results of the operations performed.

Uploaded by

magarratna471
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)

fruits = ("Apple", "Banana", "Mango", "Orange", "Papaya", "Grapes", "Mango", "Kiwi", "Custard
Apple", "Pineapple")

index = fruits.index("Custard Apple")

count = fruits.count("Mango")

print("Index of Custard Apple:", index)

print("Count of Mango:", count)

OUTPUT:-

2)

countries = ["India", "USA", "Brazil", "China", "Japan", "Germany", "France", "Italy"]

countries.append("Australia")

countries.remove("Brazil")

countries.reverse()

print(countries)

OUTPUT:-

3)

numbers = (1, 3, 5, 5, 2)

index = numbers.index(3)

count = numbers.count(5)

print("Index of 3:", index)

print("Count of 5:", count)

OUTPUT:-
4)

students = {

"John": {"age": 20, "courses": ["Math", "Science"], "CGPA": 3.8},

"Alice": {"age": 22, "courses": ["English", "History"], "CGPA": 3.9},

"Bob": {"age": 21, "courses": ["Physics", "Chemistry"], "CGPA": 3.6}

students["Wednesday"] = {"age": 23, "courses": ["Biology", "Psychology"], "CGPA": 4.0}

for s in students:

students[s]["CGPA"] += 0.1

for name, info in students.items():

print(name, info["courses"], "Updated CGPA:", info["CGPA"])

OUTPUT:-

5)

movies = ["Dangal", "PK", "3 Idiots", "Lagaan", "Swades", "Taare Zameen Par", "Chak De India",
"Zindagi Na Milegi Dobara"]

movies.append("Andhadhun")

movies.insert(2, "Dil Chahta Hai")

movies.pop()

movies.pop(1)

movies.reverse()

copied_movies = movies.copy()

print(copied_movies)

OUTPUT:-
6)

students = {

"Ravi": ["Math", "Science"],

"Neha": ["English", "History"],

"Amit": ["Geography", "Economics"]

students["Neha"] = tuple(students["Neha"])

print(students)

OUTPUT:-

You might also like