import math
[str(round(math.pi)) for i in range (1, 6)]
Answer: [‘3’, ‘3’, ‘3’, ‘3’, ‘3’]
import math
[str(round(math.pi)) for i in range (1, 6)]
Answer: [‘3’, ‘3’, ‘3’, ‘3’, ‘3’]
t=32.00
[round((x-32)*5/9) for x in t]
Answer: Error
print([i.lower() for i in "HELLO"])
Answer: [‘h’, ‘e’, ‘l’, ‘l’, ‘o’].
Answer: 1
Answer: [1, 3, 2, 1, 3, 2] .
"Welcome to Python".split()
Answer: [“Welcome”, “to”, “Python”].
names1 = ['Amir', 'Bala', 'Charlie']
names2 = [name.lower() for name in names1]
print(names2[2][0])
Answer: c
values = [[3, 4, 5, 1], [33, 6, 1, 2]]
v = values[0][0]
for lst in values:
for element in lst:
if v > element:
v = element
print(v)
Answer: 1
import copy
a=[10,23,56,[78]]
b=copy.deepcopy(a)
a[3][0]=95
a[1]=34
print(b)
Answer: [10,23,56,[78]].
a=list((45,)*4)
print((45)*4)
print(a)
Answer: 180 [45,45,45,45].
A = [[1, 2, 3],
[4, 5, 6],
[7, 8, 9]]
[A[i][len(A)-1-i] for i in range(len(A))]
Answer: [3, 5, 7]
l=[1,2,3,4,5]
[x&1 for x in l]
Answer: [1, 0, 1, 0, 1]
l1=[1,2,3]
l2=[4,5,6]
[x*y for x in l1 for y in l2]
Answer: [4, 5, 6, 8, 10, 12, 12, 15, 18]
Answer: [x for x in l if x<0]
s=["pune", "mumbai", "delhi"]
[(w.upper(), len(w)) for w in s]
Answer: [(‘PUNE’, 4), (‘MUMBAI’, 6), (‘DELHI’, 5)]
l1=[10, 20, 30]
l2=[-10, -20, -30]
l3=[x+y for x, y in zip(l1, l2)]
l3
Answer: [0, 0, 0]
Answer: [x**3 for x in l]
l=[[1 ,2, 3], [4, 5, 6], [7, 8, 9]]
[[row[i] for row in l] for i in range(3)]
Answer: [[1, 4, 7], [2, 5, 8], [3, 6, 9]]
import math
[str(round(math.pi)) for i in range (1, 6)]
Answer: [‘3’, ‘3’, ‘3’, ‘3’, ‘3’]
l1=[1,2,3]
l2=[4,5,6]
l3=[7,8,9]
for x, y, z in zip(l1, l2, l3):
print(x, y, z)
Answer:1 4 7
2 5 8
3 6 9