Python Assignment List Tuples and methods3
Python Assignment List Tuples and methods3
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.
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.