0

unpacking lists

x = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100] print(*x,sep=",") How can I put an if condition to the *x?

20th Apr 2020, 3:39 PM
Ahmad Tarek
Ahmad Tarek - avatar
4 Answers
+ 2
What exactly do you want to do with that if condition?
20th Apr 2020, 3:40 PM
HonFu
HonFu - avatar
+ 1
I think, you'd use a comprehension for this. print(*(n for n in x if not n%2), sep=',')
20th Apr 2020, 3:44 PM
HonFu
HonFu - avatar
+ 1
HonFu Thanks.It worked.
20th Apr 2020, 3:50 PM
Ahmad Tarek
Ahmad Tarek - avatar
0
HonFu I only want the even numbers with the separator "," between them
20th Apr 2020, 3:42 PM
Ahmad Tarek
Ahmad Tarek - avatar