Georg Schubert Georg Schubert - 4 months ago 8
Python Question

Can the repetition in this line be avoided?

'=' not in access and name + '.' not in access


I hope to avoid the multiplicity of
not in access
s in a line of Python code. I've used expression evaluation loops for cases of higher numbers of repetitions for convenience but it just seems odd at two.

Answer

Here's another option:

all(s not in access for s in ('=', name + '.'))

It's up to you to decide if this is simpler than your code - but at least it avoids having to write not in access twice.

Comments