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:

  1. you should remove parentheses.. python need outer ones , takes room.
  2. you're using assignment operator, not equality operator (=, not ==)
  3. what meant write foo == 'a' or foo == 'b' or ..., wrote wasn't quite correct.

Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -