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

Python Assignment List Tuples and methods3

The document outlines a Python assignment focusing on list and tuple operations, including basic, intermediate, and advanced tasks. It includes exercises such as appending to lists, counting occurrences, sorting, and manipulating tuples. The assignment aims to enhance understanding of Python data structures and their methods.

Uploaded by

nawazibrahim453
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)
16 views

Python Assignment List Tuples and methods3

The document outlines a Python assignment focusing on list and tuple operations, including basic, intermediate, and advanced tasks. It includes exercises such as appending to lists, counting occurrences, sorting, and manipulating tuples. The assignment aims to enhance understanding of Python data structures and their methods.

Uploaded by

nawazibrahim453
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

Python Assignment List Tuples and methods

Basic List Operations

1. Create a list of five numbers and append a new number to it. Print the updated list.
2. Extend a list [1, 2, 3] with another list [4, 5, 6]. Print the result.
3. Insert the string "Python" at index 2 in the list ["Java", "C++", "JavaScript",
"Ruby"].
4. Remove the first occurrence of the number 10 from the list [10, 20, 30, 10, 40].
5. Use the pop() method to remove the last element from [100, 200, 300, 400] and
print the modified list.

Intermediate List Operations

6. Count how many times the number 5 appears in the list [5, 10, 5, 20, 5, 30].
7. Sort the list [9, 1, 8, 3, 5] in ascending and descending order.
8. Reverse the list [“apple”, “banana”, “cherry”] using the reverse() method.
9. Create a copy of the list [1, 2, 3, 4, 5] and store it in another variable. Modify the
copied list and print both lists.
10. Clear all elements from a list [“hello”, “world”, “python”] using the clear()
method.

Tuple-Based Questions

11. Create a tuple with 5 different fruits and print the third fruit.
12. Convert the tuple (10, 20, 30, 40, 50) into a list, remove the number 30, and convert
it back into a tuple.
13. Try to append an element to the tuple (“A”, “B”, “C”). What happens? How can you
modify a tuple indirectly?
14. Unpack the tuple (100, 200, 300) into three separate variables and print them.
15. Count the occurrences of 7 in the tuple (7, 1, 7, 3, 7, 5).

Advanced Problems

16. Write a function that takes a list and returns a new list with all even numbers removed.
17. Create a function that accepts a list and returns a new list with elements sorted in
descending order without using the sort() method.
18. Given a list of numbers, write a program to remove all duplicate elements and print the
unique elements.
19. Given a tuple of names (“Alice”, “Bob”, “Charlie”, “Alice”, “David”), convert
it into a list, remove duplicates, and convert it back to a tuple.
20. Create a program that takes a list of mixed data types (int, str, float) and separates
integers into one list, strings into another, and floats into another.

You might also like