my_list = [i for i in range(5,0,-1)]
m=[my_list[i] for i in range(5)] if my_list[i]%2==0
print(m)
#output SyntaxError: expected 'else' after 'if' expression
Ans is D
Answer is indeed D, due to the ] before the if statement.
If this bracket wouldnt be there, the result would be [4, 2].
my_list = [i for i in range(5,0,-1)]
m = [my_list[i] for i in range(5) if my_list[i] % 2 == 0]
print(m)
[4, 2]
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
seaverick
10 months agokontra
1 year, 6 months agogekkehenk
1 year, 8 months agoandr3
1 year, 8 months agoRizos
1 year, 8 months agobesha
2 years, 4 months agoangelika_az
2 years, 6 months agomacxsz
2 years, 6 months ago