Practice Top 30 Python Programming Questions on Lists Data Structure
Q1. Write a program to find the sum of all elements in a list.
Input:
[1, 2, 3, 4, 5]
Expected Output:
Sum: 15
Q2. Write a program to find the maximum element in a list.
Input:
[10, 25, 3, 47, 5]
Expected Output:
Maximum: 47
Q3. Write a program to find the minimum element in a list.
Input:
[8, 15, 2, 9, 4]
Expected Output:
Minimum: 2
Q4. Write a program to count how many times a specific element appears in a list.
Input:
List: [3, 1, 3, 7, 3, 9]
Element: 3
Expected Output:
Count of 3: 3
Q5. Write a program to sort a list in ascending order.
Input:
[8, 3, 1, 6, 2]
Expected Output:
Sorted list: [1, 2, 3, 6, 8]
Q6. Write a program to reverse a list.
Input:
[5, 4, 3, 2, 1]
Expected Output:
Reversed list: [1, 2, 3, 4, 5]
Q7. Write a program to find the number of elements in a list.
Input:
[12, 5, 9, 3, 6]
Expected Output:
Length of list: 5
Q8. Write a program to check if a specific element exists in a list.
Input:
List: [8, 4, 7, 9, 2]
Element: 7
Expected Output:
7 exists in the list.
Q9. Write a program to concatenate two lists.
Input:
List 1: [1, 2, 3]
List 2: [4, 5, 6]
Expected Output:
Concatenated list: [1, 2, 3, 4, 5, 6]
Q10. Write a program to remove duplicate elements from a list.
Input:
[1, 2, 2, 3, 4, 4, 5]
Expected Output:
List without duplicates: [1, 2, 3, 4, 5]
Q11. Write a program to find the index of a specific element in a list.
Input:
List: [10, 20, 30, 40, 50]
Element: 30
Expected Output:
Index of 30: 2
Q12. Write a program to insert an element at a specific index in a list.
Input:
List: [1, 3, 4, 5]
Element: 2
Index: 1
Expected Output:
Updated list: [1, 2, 3, 4, 5]
Q13. Write a program to find all even numbers in a list.
Input:
[1, 2, 3, 4, 5, 6]
Expected Output:
Even numbers: [2, 4, 6]
Q14. Write a program to find all odd numbers in a list.
Input:
[1, 2, 3, 4, 5, 6]
Expected Output:
Odd numbers: [1, 3, 5]
Q15. Write a program to remove a specific element from a list.
Input:
List: [7, 8, 9, 10, 11]
Element: 9
Expected Output:
Updated list: [7, 8, 10, 11]
Q16. Write a program to create a list of squares for elements in another list.
Input:
[1, 2, 3, 4, 5]
Expected Output:
List of squares: [1, 4, 9, 16, 25]
Q17. Write a program to find the largest and smallest elements in a list.
Input:
[10, 45, 3, 22, 67]
Expected Output:
Largest: 67, Smallest: 3
Q18. Write a program to find the sum of all even numbers in a list.
Input:
[3, 6, 8, 1, 5]
Expected Output:
Sum of even numbers: 14
Q19. Write a program to find all unique elements in a list.
Input:
[3, 5, 3, 6, 7, 5]
Expected Output:
Unique elements: [6, 7]
Q20. Write a program to split a list into two halves.
Input:
[1, 2, 3, 4, 5, 6]
Expected Output:
First half: [1, 2, 3], Second half: [4, 5, 6]
Q21. Write a program to count even and odd numbers in a list.
Input:
[3, 6, 8, 1, 5, 7, 2]
Expected Output:
Even count: 3, Odd count: 4
Q22. Write a program to check if a list is a palindrome.
Input:
[1, 2, 3, 2, 1]
Expected Output:
The list is a palindrome.
Q23. Write a program to merge two lists alternately.
Input:
List 1: [1, 3, 5]
List 2: [2, 4, 6]
Expected Output:
Merged list: [1, 2, 3, 4, 5, 6]
Q24. Write a program to find the second largest element in a list.
Input:
[12, 45, 7, 22]
Expected Output:
Second largest: 22
Q25. Write a program to find common elements between two lists.
Input:
List 1: [1, 2, 3, 4]
List 2: [3, 4, 5, 6]
Expected Output:
Intersection: [3, 4]
Q26. Write a program to sort a list in descending order.
Input:
[5, 3, 8, 6, 1]
Expected Output:
Sorted list: [8, 6, 5, 3, 1]
Q27. Write a program to find the cumulative sum of elements in a list.
Input:
[1, 2, 3, 4, 5]
Expected Output:
Cumulative sum: [1, 3, 6, 10, 15]
Q28. Write a program to remove elements at odd indices from a list.
Input:
[1, 2, 3, 4, 5]
Expected Output:
Updated list: [1, 3, 5]
Q29. Write a program to multiply all the elements in a list.
Input:
[1, 2, 3, 4, 5]
Expected Output:
Product: 120
Q30. Write a program to check if a list is empty.
Input:
[]
Expected Output:
The list is empty.
Bikki Singh
Hi, I am the instructor of TechnoVlogs. I have a strong love for programming and enjoy teaching through practical examples. I made this site to help people improve their coding skills by solving real-world problems. With years of experience, my goal is to make learning programming easy and fun for everyone. Let's learn and grow together!