+ 1
Is there a way to make it shorter than I came up with? Why it happens? [RU]
mis2 contains a working, but long version and outputs the expected result. mis1 outputs not what is needed. https://code.sololearn.com/cv2JK6OrMtnw/?ref=app https://code.sololearn.com/c9lNUO83llac/?ref=app
3 Respuestas
+ 3
OK - here is a try, not finally tested. It does work with a replacement table and a list comprehension:
a = [[2,1],[3,4]] # expected output: [[10,10],[10,4]]
dic = {1:10, 2:10, 3:10} # replacement table
print([[dic.get(j,j) for ind,j in enumerate(i)] for i in a])
+ 3
Lothar
It was too good...Hope I would have got it...😁😁
+ 1
In mis1 this line does not work correct: <if a[i][j] == (2 or 1 or 3):> it has to be like in mis2.
I will try to check for a more compact version.