python - Write conditions based on a list -
i'm writing if statement in python lot of or conditions. there elegant way list, within in condition rather looping through list?
in other words, prettier following:
if foo == 'a' or foo == 'b' or foo == 'c' or foo == 'd':
i've taken python, , language has me wanting write better.
if foo in ('a', 'b', 'c', 'd'): #...
i note answer wrong several reasons:
- you should remove parentheses.. python need outer ones , takes room.
- you're using assignment operator, not equality operator (=, not ==)
- what meant write foo == 'a' or foo == 'b' or ..., wrote wasn't quite correct.
Comments
Post a Comment