vendredi 18 septembre 2020

Is there a compact way to write a repeated if condition in python? [duplicate]

Generally, there are two variations of writing repeated if conditions that I know of:

  1. Simple
if x != <something> and x != <somethingElse> and x != <somethingElse +>:
  1. Little compact
if all(x != el for el in [<something>, <somethingElse>, <somethingElse +>]

Is there a more compact way?

Aucun commentaire:

Enregistrer un commentaire