0% found this document useful (0 votes)
34 views16 pages

Worksheet - 1 List

Uploaded by

duvvieekshitha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views16 pages

Worksheet - 1 List

Uploaded by

duvvieekshitha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 16

WORKSHEET – LIST

MANIPULATION

1 What will be the output of following code-


list1=[1, 3, 2]
list1 * 2

Ans:

2 What will be the output of following code-


l="Welcome to
Python".split() l

Ans:

3 What will be the output of following code-


print([i.lower() for i in "HELLO"])

Ans:

4 What will be the output of following code-


a=[[[1,2],[3,4],5],[6,7]]
a[0][1][1]

Ans:

5 What will be the output of following code-


a,b=[3,1,2],[5,4,6]
a+b

Ans:

6 What will be the output of following


program: a=[2,1,3,5,2,4]
a.remove(2
)a
Ans:

1| Pag
e
2| Pag
e
7 Explain List Comprehension and Elegant way to create new List:

Ans:

8 What will be the output of following


program: theList=[1, 2, [1.1, 2.2]]
len(theList)

Ans:

9 What will be the output of following


program: my_list = ['p', 'r', 'o', 'b', 'l', 'e',
'm']

print('p' in my_list)

print('a' in my_list)

print('c' not in

my_list) Ans:

10 What will be the output of following


program: for fruit in
['apple','banana','mango']:
print("I like",fruit)

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:

12 What will be the output of following


program: odd = [x for x in range(20) if x
% 2 == 1]
odd

Ans:

13 What will be the output of following program:


l=[x+y for x in ['Python ','C '] for y in
['Language','Programming']] l

Ans:

14 What will be the output of following


program: odd = [1, 9]
odd.insert(1,3)
print(odd)
odd[2:2] = [5,
7]
print(odd)

Ans:

15 What will be the output of following


program: odd = [1, 3, 5]
print(odd + [9, 7, 5])
print(["re"] * 3)

Ans:

16 What will be the output of following


program: odd = [2, 4, 6, 8]
odd[0] = 1
print(odd)

5| Pag
e
odd[1:4] = [3, 5, 7]
print(odd)

Ans:

17 What will be the output of following


program: list1 = ["python", "list", 1952,
2323, 432] list2 = ["this", "is", "another",
"list"] print(list1)
print(list1[1:4])
print(list1[1:])
print(list1[0])
print(list1 * 2)
print(list1 + list2)

Ans:

18 What will be the output of following program:

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:

21 What will be the output of following


program: "Welcome to
Python4csip.com".split()

Ans:

22 What will be the output of following


program: myList = [1, 5, 5, 5, 5, 1]
max =
myList[0]
indexOfMax =
0
for i in range(1,
len(myList)): if myList[i]
> max:
max = myList[i]
indexOfMax = i
print(indexOfMax)

Ans:

23 What will be the output of the


program? m = [[x, x + 1, x + 2] for x
in range(0, 3)] m

Ans:

24 What will be the output of following


program: list("a#b#c#d".split('#'))

Ans:

25 What will be the output of following


program: values = [[3, 4, 5, 1 ], [33, 6, 1,
2]]
for row in
values:

8| Pag
e
row.sort()
for element in row:
print(element, end = " ")
print()

9| Pag
e
Ans:

26 What will be the output of following


program: data = [[[1, 2], [3, 4]], [[5, 6],
[7, 8]]]
print(data[1][0][0])

Ans:

27 What will be the output of following


program: a="hello"
b=list((x.upper(),len(x)) for x in a)
print(b)

Ans:

28 What will be the output of following


program: a=[[]]*3
a[1].append(
7) print(a))

Ans:

29 What will be the output of following


program: L1 = list()
L1.append([1, [2, 3], 4])
L1.extend([7, 8, 9])
print(L1[0][1][1] + L1[2])

Ans:

30 What will be the output of following


program: List = [True, 50, 10]
List.insert(2, 5)
print(List, "Sum is: ", sum(List))

Ans:

31 What will be the output of following


program: T = [1, 2, 3, 4, 5, 6, 7, 8]
print(T[T.index(5)], end = " ")

10 | P a g
e
print(T[T[T[6]-2]-4])

Ans:

32 What will be the output of following


program: aList = [4, 8, 12, 16]
aList[1:4] = [20, 24, 28]
print(aList)

Ans:

33 What will be the output of following


program: l = [None] * 10
print(len(l))

Ans:

34 What will be the output of following


program: sampleList = [10, 20, 30, 40,
50] sampleList.pop()
print(sampleList)
sampleList.pop(2)
print(sampleList)

Ans:

35 What will be the output of following program:


resList = [x+y for x in ['Hello ', 'Good '] for y in ['Dear',
'Bye']] print(resList)

Ans:

36 What will be the output of following


program: aList1 = [123, 'xyz', 'zara',
'abc'];
aList.insert (3,2009)
print ("Final List:::", aList)

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:

list1 = [5, 10, 15, 200, 25, 50, 20]

Ans:

39 Which function is used to reverse objects of list in place.

Ans:

40 Write a Python program to sum all the items in a list.

Ans:

12 | P a g
e
41 Write a Python program to get the largest number from a

list. Ans:

42 Write a Python program to count the number of strings where the


string length is 2 or more and the first and last character are same from
a given list of strings.
Sample List : ['abc', 'xyz', 'cbc',
'121'] Expected Result : 2
Ans:

43 Write a Python program to remove duplicates from a list.

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:

46 Python Program to Find the Second Largest Number in a List

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:

49 Program to Find Even elements in a

List: Ans:

50 Program to Print list having numbers less than


10 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:

52 WAP to display the frequency of each item in a


list. Ans:

53 What will be the output of the following program:


l=[6,12,18,24,30]
for i in l:
for j in range(1,i
%4):
print(j,'#',end=''
)
print()

Ans:

16 | P a g
e

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy