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

Python Assignment

The document provides a series of programming tasks involving lists, tuples, sets, and dictionaries in Python. Each task includes specific operations such as accessing elements, modifying lists, checking conditions, and merging data structures. The tasks are designed to demonstrate basic data manipulation techniques in Python.

Uploaded by

ermyas
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)
6 views2 pages

Python Assignment

The document provides a series of programming tasks involving lists, tuples, sets, and dictionaries in Python. Each task includes specific operations such as accessing elements, modifying lists, checking conditions, and merging data structures. The tasks are designed to demonstrate basic data manipulation techniques in Python.

Uploaded by

ermyas
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
You are on page 1/ 2

1.

Access the second-to-last element:


Given a list lst = [10, 20, 30, 40, 50], extract the second-to-last element and print it.

2. Replace the middle element:


For lst = [1, 2, 3, 4, 5], replace the middle element with 99 and print the updated list.

3. Merge two lists:


Given lst1 = [1, 2, 3] and lst2 = [4, 5, 6], create a single list that combines them without using loops or
comprehensions.

4. Extract even-indexed elements:


For lst = ['a', 'b', 'c', 'd', 'e'], create a new list containing only the elements at even indices.

5. Check if all elements are positive:


Given a list lst = [1, 2, -3, 4, 5], use a conditional statement to check if all elements are positive and
print the result.

6. Access tuple elements:


Given tup = ('apple', 'banana', 'cherry', 'date'), extract the first and last elements as a new tuple.

7. Check for membership:


For tup = (10, 20, 30, 40, 50), check if 25 exists in the tuple. Print "Yes" if it does, otherwise print
"No".

8. Concatenate tuples:
Combine tup1 = (1, 2, 3) and tup2 = (4, 5, 6) into a single tuple and print the result.

9. Find the union of two sets:


Given set1 = {1, 2, 3} and set2 = {3, 4, 5}, create a new set that contains all unique elements from
both sets.

10. Check if one set is a subset of another:


For set1 = {1, 2} and set2 = {1, 2, 3, 4}, check if set1 is a subset of set2 and print "Yes" or "No".

11. Access a value by key:


Given d = {'name': 'Alice', 'age': 30, 'city': 'New York'}, retrieve the value for the key 'city'.

12. Add a new key-value pair:


Starting with d = {'a': 1, 'b': 2}, add a new key-value pair 'c': 3 and print the updated dictionary.

13. Check if a key exists:


For d = {'x': 10, 'y': 20}, check if the key 'z' exists in the dictionary and print "Exists" or "Does not
exist".

14. Merge two dictionaries:


Combine d1 = {'name': 'Bob'} and d2 = {'age': 25} into a single dictionary.

15. Remove a key-value pair:


Given d = {'a': 1, 'b': 2, 'c': 3}, remove the key 'b' and print the updated dictionary.

You might also like