Print all even numbers in a list until a given number

后端 未结 6 1076
别跟我提以往
别跟我提以往 2020-12-12 05:38

I am just beginning to dabble in Python, and have started to go through the chapters on learnpython.org. In the \'Loops\' chapter, I have solved the challenge with the follo

6条回答
  •  长情又很酷
    2020-12-12 06:34

    you can do that using list comprehension

    The solution would be like this:

    numbers = [x for ind,x in enumerate(numbers) if x % 2== 0 and numbers[ind+1]!=237 ]
    

提交回复
热议问题