21. Merge two sorted lists
Required Input:
1 3 5, 2 4 6
Expected Output:
[1, 2, 3, 4, 5, 6]
Code In Python
def merge_sorted_lists(lst1, lst2):
# Your code here
return
Output
Click Run Button to view compiled output
22. Find the most frequent element in a list
Required Input:
1 2 3 3 2 2
Expected Output:
2
Code In Python
def most_frequent(lst):
# Your code here
return
Output
Click Run Button to view compiled output
23. Flatten a nested list
Required Input:
[[1, 2], [3, 4], [5, 6]]
Expected Output:
[1, 2, 3, 4, 5, 6]
Code In Python
def flatten_list(lst):
# Your code here
return
Output
Click Run Button to view compiled output
24. Calculate the sum of digits of a number
Required Input:
123
Expected Output:
6
Code In Python
def sum_of_digits(n):
# Your code here
return
Output
Click Run Button to view compiled output
25. Find the transpose of a matrix
Required Input:
[[1, 2], [3, 4]]
Expected Output:
[[1, 3], [2, 4]]
Code In Python
def transpose_matrix(matrix):
# Your code here
return
Output
Click Run Button to view compiled output
26. Remove all occurrences of a specified element from a list
Required Input:
1 2 3 2 4, 2
Expected Output:
[1, 3, 4]
Code In Python
def remove_element(lst, element):
# Your code here
return
Output
Click Run Button to view compiled output
27. Find the second smallest number in a list
Required Input:
4 3 1 2
Expected Output:
2
Code In Python
def second_smallest(lst):
# Your code here
return
Output
Click Run Button to view compiled output
28. Check if a number is a perfect square
Required Input:
25
Expected Output:
True
Code In Python
def is_perfect_square(n):
# Your code here
return
Output
Click Run Button to view compiled output
29. Find the sum of even numbers in a list
Required Input:
1 2 3 4 5
Expected Output:
6
Code In Python
def sum_of_even(lst):
# Your code here
return
Output
Click Run Button to view compiled output
30. Rotate a list to the right by k positions
Required Input:
1 2 3 4 5, 2
Expected Output:
[4, 5, 1, 2, 3]
Code In Python
def rotate_list(lst, k):
# Your code here
return
Output
Click Run Button to view compiled output