Worksheet - 1 List
Worksheet - 1 List
MANIPULATION
Ans:
Ans:
Ans:
Ans:
Ans:
1| Pag
e
2| Pag
e
7 Explain List Comprehension and Elegant way to create new List:
Ans:
Ans:
print('p' in my_list)
print('a' in my_list)
print('c' not in
my_list) Ans:
Ans:
3| Pag
e
4| Pag
e
11 What will be the output of following
program: pow2 = [2 ** x for x in
range(10) if x > 5] pow2
Ans:
Ans:
Ans:
Ans:
Ans:
5| Pag
e
odd[1:4] = [3, 5, 7]
print(odd)
Ans:
Ans:
l=[10,20,30,40,50,60]
for i in
range(1,6):
l[i-1]=l[i]
for i in
range(0,6):
print(l[i],end=''
)
Ans:
6| Pag
e
19 What will be the output of following
program: l=[6,12,18,24,30]
for i in l:
for j in range(1,i%5):
print(j,'#',end='')
print()
Ans:
7| Pag
e
20 What will be the output of following
program: names = ['Hardik', 'Virat',
'Rahul', 'Dhavan'] print(names[-1][-1])
Ans:
Ans:
Ans:
Ans:
Ans:
8| Pag
e
row.sort()
for element in row:
print(element, end = " ")
print()
9| Pag
e
Ans:
Ans:
Ans:
Ans:
Ans:
Ans:
10 | P a g
e
print(T[T[T[6]-2]-4])
Ans:
Ans:
Ans:
Ans:
Ans:
Ans:
11 | P a g
e
37 What will be the output of following
program: A = [2, 4, 6, 8,10]
L = len (A)
S=0
for I in range (1, L, 2):
S+=A[I]
print("Sum=",S)
Ans:
38
Given a Python list, find value 20 in the list, and if it is present, replace it
with
200. Only update the first occurrence of a value
list1 = [5, 10, 15, 20, 25, 50, 20]
Expected output:
Ans:
Ans:
Ans:
12 | P a g
e
41 Write a Python program to get the largest number from a
list. Ans:
Ans:
13 | P a g
e
44 Write a program to shift every element of a list to circularly right.
E.g.- INPUT : 1 2 3 4 5
OUTPUT : 5 1 2 3 4
Ans:
45 Take a list of 10 elements. Split it into middle and store the elements in
two dfferent lists. E.g.-
INITIAL list :
58 24 13 15 63 9 8 81 1 78
After spliting :
58 24 13 15 63
9 8 81 1 78
Ans:
Ans:
47
What will be the output of the following program:
14 | P a g
e
l=[10,20,30,40,50,60]
for i in range(len(l)): if(i
%2==0):
print(l[i],end='#')
else:
print(l[i])
Ans:
48
What will be the output of the following program:
l=[10,20,30,40,50,60]
for i in range(len(l)): if(i
%2==0):
print(l[i],end='#')
else:
print(l[i],end='@')
Ans:
List: Ans:
15 | P a g
e
51 What will be the output of following
program: l=[[i*j for j in range(1,11)] for i
in range(7,9)]
l
Ans:
Ans:
16 | P a g
e