Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 9
List comprehension print(list(i+1 if i%2==0 else i-1 for i in range(50)))
11th Jul 2020, 12:53 PM
Abhay
Abhay - avatar
+ 4
[i+1 if i%2==0 else i-1 for i in range(50) ]
11th Jul 2020, 12:58 PM
Мг. Кнап🌠
Мг. Кнап🌠 - avatar
+ 3
мʀυηαlι ʀαנρυт usually we create a list of items using this shorthand expression: [i for i in range(50)] , now we are just checking if that i%2 results in 0 ,if yes do i+1 else do i-1 so it takes this form [i+1 if i%2==0 else i-1 for i in range(50)] I think if you read it carefully it's self explanatory ,
11th Jul 2020, 1:27 PM
Abhay
Abhay - avatar
+ 1
как дела???
13th Jul 2020, 7:48 AM
Глеб
+ 1
Use list comprehension
15th Jul 2020, 3:30 PM
Sai Baba
Sai Baba - avatar