What will be the output of the following Python code?
A = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] [A[i][i] for i in range(len(A))]
[1, 5, 9]
[3, 5, 7]
[4, 5, 6]
[2, 5, 8]
l=[[1, 2, 3], [4, 5, 6]] for i in range(len(l)): for j in range(len(l[i])): l[i][j]+=10 l
No output
Error
[[1, 2, 3], [4, 5, 6]]
[[11, 12, 13], [14, 15, 16]]
A = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] [[col + 10 for col in row] for row in A]
[[11, 12, 13], [14, 15, 16], [17, 18, 19]]
[11, 12, 13], [14, 15, 16], [17, 18, 19]
[11, 12, 13, 14, 15, 16, 17, 18, 19]
A = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] [A[i][len(A)-1-i] for i in range(len(A))]
r = [11, 12, 13, 14, 15, 16, 17, 18, 19] A = [[0, 10, 20], [30, 40, 50], [60, 70, 80]] for row in A: for col in row: r.append(col+10) r
[11, 12, 13, 14, 15, 16, 17, 18, 19, 10, 20, 30, 40, 50, 60, 70, 80, 90]
[10, 20, 30, 40, 50, 60, 70, 80, 90]
[0, 10, 20, 30, 40, 50, 60, 70, 80]
A = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] B = [[3, 3, 3], [4, 4, 4], [5, 5, 5]] zip(A, B)
Address of the zip object
Address of the matrices A and B
[3, 6, 9, 16, 20, 24, 35, 40, 45]
[1, 2, 3]
(1, 2, 3)
{1, 2, 3}
{}
print(t[3])
t[3] = 45
print(max(t))
print(len(t))
>>>t=(1,2,4,3)
>>>t[1:3]
(1, 2)
(1, 2, 4)
(2, 4)
(2, 4, 3)
>>>t[1:-1]
>>>t = (1, 2, 4, 3, 8, 9)
>>>[t[i] for i in range(0, len(t), 2)]
[2, 3, 9]
[1, 2, 4, 3, 8, 9]
[1, 4, 8]
(1, 4, 8)
d = {"john":40, "peter":45}
d["john"]
40
45
“john”
“peter”
>>>t = (1, 2)
>>>2 * t
(1, 2, 1, 2)
[1, 2, 1, 2]
(1, 1, 2, 2)
[1, 1, 2, 2]
>>>t1 = (1, 2, 4, 3)
>>>t2 = (1, 2, 3, 4)
>>>t1 < t2
True
False
None
>>>my_tuple = (1, 2, 3, 4)
>>>my_tuple.append( (5, 6, 7) )
>>>print len(my_tuple)
1
2
5
numberGames = {}
numberGames[(1,2,4)] = 8
numberGames[(4,2,1)] = 10
numberGames[(1,2)] = 12
sum = 0
for k in numberGames:
sum += numberGames[k]
print len(numberGames) + sum
30
24
33
12
Tuple
Integer
List
Both tuple and integer
Error, tuple slicing doesn’t exist
[2,3]
(2,3,4)
(2,3)
>>> a=(1,2,(4,5)) >>> b=(1,2,(3,4)) >>> a<b
Error, < operator is not valid for tuples
Error, < operator is valid for tuples but not if there are sub-tuples
>>> a=("Check")*3 >>> a
(‘Check’,’Check’,’Check’)
* Operator not valid for tuples
(‘CheckCheckCheck’)
Syntax error