Python_list_questions
Python_list_questions
1. Write a Python program to find the maximum element in a list of numbers without
max functions
numbers = [10, 20, 4, 45, 99]
The maximum element is: 99
2. Write a Python program to sum all the elements in a list of numbers.
a. numbers = [10, 20, 30, 40]
b. The sum of all elements is: 100
3. Write a Python program to reverse a list without reverse or slicing operator
a. numbers = [1, 2, 3, 4, 5]
b. Reversed list: [5, 4, 3, 2, 1]
4. Write a Python program to sort a list in ascending order without sort functions
5. Write a Python program to remove duplicates from a list while maintaining the order
of elements.
a. numbers = [1, 2, 2, 3, 4, 4, 5]
b. List after removing duplicates: [1, 2, 3, 4, 5]
6. Write a Python program to find all pairs of numbers in a list that add up to a specific
target sum.
a. numbers = [1, 2, 3, 4, 3, 5, 6] target_sum = 6
b. Pairs that add up to 6: [(3, 3), (2, 4), (1, 5)]
7. Write a Python program to flatten a nested list (list within lists) into a single list.
a. nested_list = [1, [2, 3], [4, [5, 6], 7], 8]
b. Flattened list: [1, 2, 3, 4, 5, 6, 7, 8]
8. Write a Python program to find the sum of the elements in a list, excluding the largest
and smallest element. Don’t use max or min functions
a. numbers = [1, 2, 3, 4, 5]
b. Sum excluding the largest and smallest element: 9
Intermediate
9. Write a Python program to check if a list is a palindrome (reads the same backward
as forward) using two pointer approach
a. numbers = [1, 2, 3, 2, 1]
b. True
10.Write a function to remove duplicate elements from a list.
a. numbers = [1, 2, 3, 2, 4, 5, 1, 6]
b. [1, 2, 3, 4, 5, 6]
11. Find Common Elements in Two Lists
a. list1 = [1, 2, 3, 4, 5]
b. list2 = [3, 4, 5, 6, 7]
c. Result: [3, 4, 5]
12.Find the Longest Word in a List
a. words = ["apple", "banana", "strawberry", "kiwi"]
b. Strawberry
13.Find Missing Number in a List
Advanced