Lists in Python (1)
Lists in Python (1)
2. Which of the following methods is used to add an element to the end of a list in Python?
a) add()
b) insert()
c) append()
d) extend()
4. How can you remove the last item from a list in Python?
a) remove()
b) del
c) pop()
d) discard()
5. Which of the following is the correct syntax to access the second last element of a list list
= [10, 20, 30, 40, 50]?
a) list[-1]
b) list[2]
c) list[-2]
d) list[1]
12. What is the default index of the first element in a Python list?
a) 1
b) 0
c) -1
d) None
28. Which of the following methods is used to remove an element from a specific position in a
list?
a) remove()
b) pop()
c) delete()
d) discard()
29. Which of the following operations will add an element to the beginning of a list?
a) list.insert(0, element)
b) list.append(element)
c) list.extend([element])
d) list[0] = element
30. What will the following code return?
list = [1, 2, 3, 4, 5]
list[::2]
a) [1, 3, 5]
b) [2, 4]
c) [1, 2, 3, 4, 5]
d) [1, 4]
34. Which of the following functions can be used to create a list from a string?
a) list()
b) split()
c) to_list()
d) string_to_list()
6. Given the list l = [45, 30, 15, 60, 25]. Write the python statement to perform the following:
(i) to print the 3rd element from the list.
(ii) to print the 2nd, 3rd and 4th element from the list.
(iii) to print the list in reverse.
(iv) to print the last element from the list.
(v) to print the sum of the elements of the list.
(vi) to print the lowest element.
(vii) to print the greatest element.
(viii) to print the total number of elements present in the list.
7. Write python program to get n number of integer number as input and add them into a list.
8. Write python program to print the elements of the list separated by ‘&’.
9. Given a list l consisting of integer numbers, write python program for each of the following
(i) to find the maximum and minimum number without using built in min() and max()
functions.
(ii) to find the sum and average without using the built in function sum() and len().
(iii) to get an integer element as input and then search and display its index if element found
else print “Element not found” in the list.
(iv) to add the even numbers to a list named even and odd numbers to a list named odd.
(v) to add 10 to even numbers and 20 to odd numbers.
(vi) to add 20 to elements at even index position and 40 to elements at odd index position.
(vii) to swap the elements available odd index position with its previous element.
(viii) to shift the largest element to end of the list.
(ix) To display the numbers divisible by both 7 and 11. Display “None of number is divisible
by both 7 and 11” if no number is divisible by 7 and 11.
(x) to display all the 4 digit number from the list.
(xi) to display the prime numbers from it.
(xii) to display the perfect numbers in it.
10. Given a list consisting of string(words) as element. Write a python program to print the largest
word from the list.
11. Given a list containing nested lists with each nested list containing elements with structure,
studentID, name, class and mark...
students = [ [201, "Arun Kumar", "11", 87],
[202, "Meenakshi R", "12", 82],
[203, "Rajeshwari Nair", "12", 100],
[204, "Suresh Babu", "11", 76],
[205, "Anitha Subramaniam", "11", 99] ]
12. Given a list named ‘names’.. Write a python program to remove the last element and print it.
Also, if the list is empty then a message “List empty” is to be printed.
13. Given a list named ‘names’.. Write a python program to remove and print all the elements and
finally print “List empty” when all the elements have been removed(Even if list is empty in
beginning).
14. Given a list named ‘names’.. Write a python program to print the top element(last element)
from the list. If the list is empty then it should print “List empty”
15. Given a list named ‘names’.. Write a python program to print all the elements in reversed order.
If the list is empty then it should print “List empty”.
16. Given a list named ‘names’.. Write python program to print those words which doesn’t consist
of vowels in it.