+ 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

14th May 2020, 4:03 PM
PAL
PAL - avatar
3 Réponses
+ 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])
14th May 2020, 4:59 PM
Lothar
Lothar - avatar
+ 3
Lothar It was too good...Hope I would have got it...😁😁
14th May 2020, 5:04 PM
Kiran Deep Naidu
Kiran Deep Naidu - avatar
+ 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.
14th May 2020, 4:22 PM
Lothar
Lothar - avatar