0% found this document useful (0 votes)
4 views

Lists in Python

Uploaded by

parvgrover15
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Lists in Python

Uploaded by

parvgrover15
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

LISTS IN PYTHON-OUTPUTS & PROGRAMS

Q1. Write a Python code to remove all even numbers from the given list L=[2,7,12,5,10,15,23].

Q2. Write a Python code to input a number and count the occurrences of that number in a given list of numbers.
L=[10,20,30,40,10,50,10]

Q3. Write a Python code to input a number and print the position of that number if exists. If number is not
present print Number “is not present in list”. Given list is L=[10,20,30,40,10,50,10].

Q4. Write a Python code to accept a list of numbers and prints the minimum value in that list along with its
index no.

Q5. Write a Python code to accept a list of numbers and prints the maximum value in that list along with its
index no.

Q6. Write a Python code to accept a list of numbers and prints the sum of all numbers in that list.

Q7. Write a Python code to accept a list of numbers and prints the product of all numbers in that list.

Q8. Write a Python code to accept a list of numbers and prints the sum of alternate numbers in that list starting
from 0 index position.

Q9. Write a Python code to accept a list of numbers and prints the sum and product of all odd positions in that
list.(i.e. odd positions are 1,3,5,7 etc.)

Q10. Write a Python code to accept a list of numbers and modify list in such a way that it adds 5 in all odd
values entered and add 10 in all even values entered of list. Also display the original List & modified list.

Q11. Write a Python code to display unique and duplicate numbers of given list L1 into L2 and L3. List L2
should contain all unique numbers of L1 and list L3 should contain all duplicate numbers of L1. Given
list L1 is: L1=[2,7,1,4,9,5,1,4,3]

Q12. Write a Python code to exchange first half side elements of list with second half side elements of list
assuming that list is having even number of elements.

Q13. Write a Python code to accept a list of integers L1 and creates 2 lists named square and cube in which
square list will contain squares of values of list L1and cube list will contain cubes of values of list L1.
Also display both the lists.

Q14. Write a Python code to accept a list of integers and prints the reverse of that list. Also display the
original and reversed list.

Q15. Write a Python code to display the frequencies of all the elements of list L in Lists L1 and L2. For example
if List L=[3,21,5,6,3,8,21,6] L1 will contain frequency and L2 will contain elements.

Q16. Given a heterogeneous list, Write a python code to display square of a element of a list if it is an
integer and change the case if element is a string. List will contain both numbers and strings.

Q17. Write a python code to accept a list of strings and display those strings in that list which are starting with
‘A’ or ‘a’ and as well their count.
Q18. Write a Python code to accept a list of integers L and display the sum of all the values which are ending
with 4 from the list.

Q19. Write a Python code to accept a list of integers Num to swap the value which is divisible by 7 with very
next value presented in list.
For example: If list L is[3,21,5,6,14,8,14,3] then list L will become [3,5,21,6,8,14,3,14]

Q20. Write a Python code to accept a list of integers L and modify the list in such a way that alternate positions
will be swapped. For example if list contains [10,20,30,40] then result will be [20,10,40,30].

Q21. Write a Python code to input two list L and M with same size and adds their elements together to form a
new list N whose elements are sum of corresponding elements in L and M. For example if L contains
L=[3,1,4] and M=[1,5,9] then N should contain [4,6,13].

Q22. Write a Python code to input a list of integers and reposition the list in such a way by shifting each element
one by one before and shifting the first element to last position. Also display the original & resultant list.
Consider the example if list is [10,20,30,40] then after shifting it looks like [20,30,40,10].

Q23. Write a python code to accept a list of strings L. Create a new list L1 that consists of strings from L with
their first character removed. Also display the original and new list.

Q24. Write a Python code to input a list of integers containing numbers between 1 and 12. Then it will replace
all the entries in that list that are greater than 10 with value 10. Also display the resultant list.
Q25. Suppose L=[“Aman”,[14,11,2019],4,450,“Pen Drive”]
Consider the above list L and answer the following:
(i) L[3:] (iv) L[-2] (vii) L[1][1]
(ii) L[::2] (v) L[-2:] (viii) L[-4][-1]
(iii) L[1:2] (vi) L[-2:-5:-2] (ix) L[0]
Q26. What is the difference between following two expressions if A is given as [1,2,3]. Also predict output.
(i) A*3 (ii)A*=3
Q27. Given a list L1=[2, 9.3, 14, 20.3, [3,9,12], 90]
(a) Which list slice will return [2, 9.3, 14, 20.3, [3,9,12]]
(b) Which expression will return [3, 9, 12]
(c) Which expression will return [[3, 9, 12]]
(d) Which list slice will return [9.3, 20.3 ,90]

Q28. Write the output of the following Python Codes:


(i) s=“Lists” (ii) L=[2,8,6,4,8,19,8,5,3,21,22] (iii) L=[‘p’,‘a’,‘s’,‘s’,‘w’,‘o’,‘r’,‘d’]
print(list(s)) a=L.count(8) L.remove(‘s’ )
print(a) print(L)
L.pop( )
(v) L=[11,46,3,21,31,41] del L[1]
(iv)L=[10,20,30,40,50] L.sort( ) print(L)
L.clear( ) print(L)
print(L) L.reverse( )
print(L)
Q29. Write the output of the following Python codes:

(i) L1=[500,600] (ii) L=[ ]


L2=[35,45] L1=[ ]
L1.append(700) L2=[ ]
L1.extend(L2) for i in range(6,10):
L1.insert(25,2) L.append(i)
print(L1) for i in range(10,4,-2):
print(L1+L2) L1.append(i)
print(L1.index(35)) for i in range(len(L1)):
print(L2*2) L2.append(L[i]+L1[i])
L2.append(len(L)-len(L1))
print(L2)

Q30. Suppose L=[10,[“few”,“facts”,“fun”],3, “Good”]


Consider the above list L and answer the following:
(i) L[3:] (ii) L[::2] (iii) L[1:2] (iv) L[1][2]

Q31. Predict the output of following Python Codes:

(i) L1=[10,30,50,70,90]
print(L1==L1.reverse( ))
print(L1)

(ii) my_list=['q','u','e','s','t','i','o', 'n']


my_list[2:3]=[ ]
print(my_list)
my_list[2:5]=[ ]
print(my_list)

(iii) list1=[13,18,11,16,13,18,13]
print(list1.index(18))
print(list1.count(18))
list1.append(list1.count(13))
print(list1)

You might also like