+ 4
How to print [odd,even,odd,even,odd] for 1 to 5 number using list comprehension in python
Above output may be printed using for loop but I want to my output using only list comprehension (must include if else list comprehension) not other methods
9 ответов
+ 9
a=["odd" if i%1==0 else "even" for i in range(1,6)]
+ 6
But I assumed he knew how do list comprehension ,but isn't aware of how to add if else in list comprehension ,so I gave the code
+ 4
Yup!
+ 4
Thanks everyone well explained
I understand easily
+ 3
Your attempt?
You won't get ready-made code, show your code/attempt we will fix together.
+ 3
𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 Abhay No problem guys 😊
At the end of the day if he has learnt something new, then we should be happy.
+ 2
Yeah 𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 you too are right because struggling and thinking a bit makes us clever and a good problem solver.