简体   繁体   中英

Python “for” inside “any” syntax error?

I have a piece of code that broke the other day and I can't find the problem. I need to do something if I find a coincidence between a user input and the first value of any element of a list of lists. I had this code running in another computer, but somehow I can't make it run anymore:

if any(orderinput == x[0] for x in order):

orderinput is the user input and order is the list of lists. This worked once and should be working based on what I've read here on stackoverflow, but it throws a syntax error at the r in for .

I tried moving it between lines or adding spaces, but the error follows the r .

I'm working in Python 2.2. I don't remember the version in the machine I made the code.

Generator expressions are available since python 2.4. Try changing to a list comprehension:

if any([orderinput == x[0] for x in order]):

Python 2.2 is twelve years old. A lot of things were different.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM