expected result from 'map' not getting

Question:

I expect to get the following result but i cant. can anyone help?
[[2, 4, 6], [8, 10, 12], [14, 16, 18], [20, 22, 24]]

A=[]
B=[]
C=[]

lst = [ [1,2,3], [4,5,6], [7,8,9], [10,11,12] ]  

for A in lst:

    B = list(map(lambda x=B : x*2 for B in A , A)
    C.append(B)

print(C)
Asked By: Ham

||

Answers:

lst = [ [1,2,3], [4,5,6], [7,8,9], [10,11,12] ]

If you want to keep your initial approach:

C=[]
for A in lst:
    B = list(map(lambda x : x*2 , A))
    C.append(B)

print(C)

A simpler way to do it:

C=[]
for A in lst:
    B = [x*2 for x in A]
    C.append(B)

print(C)

And even more simply, using list comprehension:

C = [[x*2 for x in B] for B in lst]

print(C)
Answered By: Swifty
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.