Easy Questions (10)
- Create a list of 5 numbers and display it.
- Write a program to find the length of a list without using len().
- Add an element to an existing list at the end.
- Insert an element at the second position of a list.
- Write a program to count occurrences of an element in a list without using count().
- Remove the first occurrence of a specific element from a list.
- Display all elements of a list using a loop.
- Find the sum of all elements in a list.
- Write a program to reverse a list using a method.
- Create a list with mixed data types and print it.
Medium Questions (6)
Write a program to find the maximum and minimum numbers in a list.
Input:[4, 10, 23, 1, 9]
Output:Maximum: 23, Minimum: 1
Sort a list of numbers in ascending and descending order.
Input:[15, 3, 8, 22, 7]
Output:Ascending: [3, 7, 8, 15, 22]
Descending: [22, 15, 8, 7, 3]
Write a program to remove duplicates from a list.
Input:[2, 3, 5, 2, 9, 3, 7]
Output:[2, 3, 5, 9, 7]
Create two lists, merge them, and sort the resulting list.
Input:List1: [4, 8, 12]
List2: [3, 9, 11]
Output:Merged and Sorted List: [3, 4, 8, 9, 11, 12]
Write a program to find the second largest element in a list.
Input:[18, 29, 10, 45, 35]
Output:Second Largest: 35
Given a list, check if an element exists in the list without using the
in
keyword.
Input:List: [7, 5, 12, 17, 9]
Element: 12
Output:Element found in the list
Hard Questions (4)
Write a program to rotate the elements of a list by a given number of positions.
Input:List: [1, 2, 3, 4, 5]
Rotate by: 2
Output:Rotated List: [4, 5, 1, 2, 3]
Split a list into two halves and merge them after reversing one half.
Input:List: [10, 20, 30, 40, 50, 60]
Output:First Half: [10, 20, 30]
Reversed Second Half: [60, 50, 40]
Merged List: [10, 20, 30, 60, 50, 40]
Write a program to create a list of numbers from 1 to 50, and remove all multiples of 3 and 5.
Input:List: [1, 2, 3, 4, ..., 50]
Output:Filtered List: [1, 2, 4, 7, 8, 11, ... , 47, 49]
Implement matrix addition using lists of lists (2D lists).
Input:Matrix A: [[1, 2], [3, 4]]
Matrix B: [[5, 6], [7, 8]]
Output:Resultant Matrix: [[6, 8], [10, 12]]