What will be the output of the following Python code?
matrix = [[1, 2, 3, 4], [4, 5, 6, 7], [8, 9, 10, 11], [12, 13, 14, 15]] for i in range(0, 4): print(matrix[i][1], end = " ")
def m(list): v = list[0] for e in list: if v < e: v = e return v values = [[3, 4, 5, 1], [33, 6, 1, 2]] for row in values: print(m(row), end = " ")
data = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]] def ttt(m): v = m[0][0] for row in m: for element in row: if v < element: v = element return v print(ttt(data[0]))
points = [[1, 2], [3, 1.5], [0.5, 0.5]] points.sort() print(points)
a=[10,23,56,[78]] b=list(a) a[3][0]=95 a[1]=34 print(b)
lst=[3,4,6,1,2] lst[1:2]=[7,8] print(lst)
a=[1,2,3] b=a.append(4) print(a) print(b)
a=[13,56,17] a.append([87]) a.extend([45,67]) print(a)
word1="Apple" word2="Apple" list1=[1,2,3] list2=[1,2,3] print(word1 is word2) print(list1 is list2)
def unpack(a,b,c,d): print(a+d) x = [1,2,3,4] unpack(*x)
places = ['Bangalore', 'Mumbai', 'Delhi'] places1 = places places2 = places[:] places1[1]="Pune" places2[2]="Hyderabad" print(places)
a= [1, 2, 3, 4, 5] for i in range(1, 5): a[i-1] = a[i] for i in range(0, 5): print(a[i],end = " ")
a = [1, 5, 7, 9, 9, 1] <br class="blank" />b=a[0] <br class="blank" />x= 0 for x in range(1, len(a)): if a[x] > b: b = a[x] b= x print(b)
a=["Apple","Ball","Cobra"] a.sort(key=len) print(a)
num = ['One', 'Two', 'Three'] for i, x in enumerate(num): print('{}: {}'.format(i, x),end=" ")
What will be the output of the following Python code snippet?
k = [print(i) for i in my_string if i not in "aeiou"]
What is the output of print(k) in the following Python code snippet?
k = [print(i) for i in my_string if i not in "aeiou"] print(k)
my_string = "hello world" k = [(i.upper(), len(i)) for i in my_string] print(k)
x = [i**+1 for i in range(3)]; print(x);
print([i.lower() for i in "HELLO"])
print([i+j for i in "abc" for j in "def"])
print([[i+j for i in "abc"] for j in "def"])
print([if i%2==0: i; else: i+1; for i in range(4)])
l=[1,2,3,4,5] [x&1 for x in l]
l1=[1,2,3] l2=[4,5,6] [x*y for x in l1 for y in l2]
s=["pune", "mumbai", "delhi"] [(w.upper(), len(w)) for w in s]
l1=[10, 20, 30] l2=[-10, -20, -30] l3=[x+y for x, y in zip(l1, l2)] l3
import math [str(round(math.pi)) for i in range (1, 6)]
Read the information given below carefully and write a list comprehension such that the output is: [‘e’, ‘o’]
w="hello" v=('a', 'e', 'i', 'o', 'u')
[ord(ch) for ch in 'abc']
t=32.00 for x in t: print(x)
Write a list comprehension equivalent for the Python code shown below.
for i in range(1, 101): if int(i*0.5)==i*0.5: print(i)
What is the list comprehension equivalent for?
{x : x is a whole number less than 20, x is even} (including zero)
What will be the output of the following Python list comprehension?
[j for i in range(2,8) for j in range(i*2, 50, i)]
l=["good", "oh!", "excellent!", "#450"] [n for n in l if n.isalpha() or n.isdigit()]
A = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] A[1]
Which of the following Python statements will result in the output: 6?
A = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
A = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] [A[row][1] for row in (0, 1, 2)]
A = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] [A[i][i] for i in range(len(A))]
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
A = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] [[col + 10 for col in row] for row in A]
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
A = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] B = [[3, 3, 3], [4, 4, 4], [5, 5, 5]] [[col1 * col2 for (col1, col2) in zip(row1, row2)] for (row1, row2) in zip(A, B)]
A = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] B = [[3, 3, 3], [4, 4, 4], [5, 5, 5]] zip(A, B)
>>>t=(1,2,4,3)
>>>t[1:3]
>>>t[1:-1]
>>>t = (1, 2, 4, 3, 8, 9)
>>>[t[i] for i in range(0, len(t), 2)]
d = {"john":40, "peter":45}
d["john"]
>>>t = (1, 2)
>>>2 * t
>>>t1 = (1, 2, 4, 3)
>>>t2 = (1, 2, 3, 4)
>>>t1 < t2
>>>my_tuple = (1, 2, 3, 4)
>>>my_tuple.append( (5, 6, 7) )
>>>print len(my_tuple)
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
>>> a=(1,2,(4,5)) >>> b=(1,2,(3,4)) >>> a<b
>>> a=("Check")*3 >>> a
>>> a=(1,2,3,4) >>> del(a[2])
>>> a=(2,3,4) >>> sum(a,3)
Is the following Python code valid?
>>> a=(1,2,3,4) >>> del a
>>> a=(0,1,2,3,4) >>> b=slice(0,2) >>> a[b]
>>> a,b,c=1,2,3 >>> a,b,c
>>> a,b=1,2,3
>>> a=(1,2) >>> b=(3,4) >>> c=a+b >>> c
>>> a,b=6,7 >>> a,b=b,a >>> a,b
>>> import collections >>> a=collections.namedtuple('a',['i','j']) >>> obj=a(i=4,j=7) >>> obj
>>> a=2,3,4,5 >>> a
>>> a=(2,3,1,5)
>>> a.sort()
>>> a
>>> a=(1,2,3) >>> b=a.update(4,)
>>> a=[(2,4),(1,2),(3,9)] >>> a.sort() >>> a
nums = set([1,1,2,3,3,3,4,4])
print(len(nums))
a = [5,5,6,7,7,7]
b = set(a) def test(lst): if lst in b: return 1 else: return 0 for i in filter(test, a):
print(i,end=" ")
>>> a={5,4} >>> b={1,2,4,5} >>> a<b
>>> a={4,5,6} >>> b={2,8,6} >>> a+b
>>> a={4,5,6} >>> b={2,8,6} >>> a-b
>>> a={5,6,7,8} >>> b={7,8,10,11} >>> a^b
>>> s={5,6} >>> s*3
>>> a={3,4,5} >>> b={5,6,7} >>> a|b
a={3,4,{7,5}} print(a[2][0])
>>> a=frozenset([5,6,7])
>>> a.add(5)
>>> a={3,4,5}
>>> a.update([1,2,3])
>>> a={1,2,3}
>>> a.intersection_update({2,3,4,5})
>>> b=a >>> b.remove(3)
>>> b=a.copy() >>> b.add(4)
>>> b=a.add(4)
>>> b
>>> b=frozenset([3,4,5])
>>> a-b