Georg Schubert Georg Schubert - 1 year ago 145
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 Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download