Consider a list of numbers and apply following operations:
List1=[1,3,5,7,9]
List2=[2,4,6,8,10]
List3=[“red”,”green”,”blue”]
1. Find minimim element from the list1
2. Find maximum element from list2
3. Find the sum of elements of list1 and list2
4. Print all numbers greater than 5 from list1.
5. Concatenate 2 lists and print the final list
6. Insert 11 in list1 at 3rd index.
7. Delete 2nd element from list2.
8. Repeat the elements three times in list3.
9. Sort list 3 in descending order
10. Check whether 20 exists in list2 or not.
11. Change “10” to 100 in list 2.
12. Replace “1,3,5” with 11 and 13 in list 1.
13. Delete 3rd element from list 2.
14. Join list 1 and list 2.
15. Delete list 3.
Question: Write a program to print index numbers of minimum and
maximum element.
Solution:
list = [10, 1, 2, 20, 3, 20]
# min element's position/index
min = list.index (min(list))
# max element's position/index
max = list.index (max(list))
# printing the position/index of
# min and max elements
print("position of minimum element: ", min)
print("position of maximum element: ", max)
Question: Turn every item of a list into its square
Solution:
numbers = [1, 2, 3, 4, 5, 6, 7]
res = [x * x for x in numbers]
print(res)
Question: Program to remove duplicate elements from list
Solution:
# declare list
list1 = [10, 20, 10, 20, 30, 40, 30, 50]
# creating another list with unique elements
# declare another list
list2 = []
# appending elements
for n in list1:
if n not in list2:
list2.append(n)
# printing the lists
print("Original list")
print("list1: ", list1)
print("List after removing duplicate elements")
print("list2: ", list2)