Programs based on Lists
1. Consider a list of marks :Marks=[20,25,25,27] . WAP to increase all the marks in the list by 20.
2. WAP to create a list of even numbers between 1 and n (input by the user) using list comprehension.
3. WAP to add an element to the end of a list. The element can be a number, word, list of numbers from 1 to n or a list of random elements.
Sample Run:
What do you want to add to the list
1. Number
2. Word
3. A list of numbers from 1 to n
4. A list of n elements
Enter choice :2
Enter Word :looping
[24, 'Helicopter', 4500.34, 'looping']
4. WAP to add an element in a list at a given location.
Sample Run:
List : [11, 60, 22, 44]
Enter number to be inserted :78
Enter position :2
[11, 60, 78, 22, 44]
5. WAP to add another list to an existing list.
Sample Run:
List : [11, 60, 22, 44]
Enter number of elements of list 2 :4
Enter element :11
Enter element :89
Enter element :loop
Enter element :wings
Updated List : [11, 60, 22, 44, '11', '89', 'loop', 'wings']
6. WAP to find out the number of occurrences of a given element(input by the user) in a list.
7. WAP to search for a given element in the list and display its index.
8. WAP to find the sum of elements stored in a list.
9. WAP to create a list of numbers between 1 and n(input by the user) that are divisible by 3 or 7 using list comprehension and find the value of the minimum and maximum element in it. Also display the length of the list.
10. WAP to remove the last n elements from a list of values.
Sample Run:
List : [22, 34, 56, 24, 78, 90]
Enter number of elements to be removed from the end :2
New List : [22, 34, 56, 24]
11. WAP to show the duplicate elements in a list of elements.
Sample Run:
List is : [20, 25, 35, 24, 20, 70, 80, 18, 35]
The Duplicate elements are:
20 35
12. WAP to calculate the total number of zeros, positive and negative elements in the list.
13. WAP to create a list using names of your friends, then search for your best friend 's name in the list.
14. WAP to declare two list. Now find and display the common elements between two lists.
15. WAP to declare a list of your favorite cities. Display the list sorted in increasing order of the length of the name of the cities.
16. WAP to enter a list of numbers. Swap adjacent elements of the list and display.
- Do NOT use second list.
- Assume the list is even
Suppose the list contains:
L1=[22, 34, 67,56, 9, 24, 45, 90]
The changed list should contain:
L1=[34,22, 56, 67, 24, 9, 90, 45]
17. WAP to enter a list and count the number of unique values in it.
18. WAP to enter a list and count the number of numeric and non numeric values in it.
Suppose the list contains:
L1=["Blue', 34, 'A', 67.5, 56, "Even', 'odd', 45, 90]
The output will be:
Number of non-numeric values: 4
Number of numeric values: 5
19. WAP to enter a list of words in Python and reverse each word in the list.
20. WAP to create a list of 4 numbers. From the list create 4 other lists to store the first 4 multiples of the given numbers.
Suppose the list contains:
L1= [2, 9, 4, 6]
T4 new lists would be:
L2=[2,4,6,8]
L3=[9,18,27,36]
L4=[4,8,12,16]
L5=[6,12,18,24]