0

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

I hope to avoid the multiplicity of not in accesss 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.

  • 1
    I think you answered your own question is some way: is it really worth it? – Julien Aug 04 '16 at 03:53
  • It just seems so unpythonic. –  Aug 04 '16 at 03:55
  • `re.search('=|' + name + '[.]', access) is None` avoids the repetition, but I don't think mine is any better than yours. – Robᵩ Aug 04 '16 at 03:55
  • I don't think using an arguably obscure and just as long expression just for the sake of not repeating 3 words is more pythonic... – Julien Aug 04 '16 at 03:59
  • I kind of expected something aesthetically pleasing like `'=', name + '.' not in access`, I guess. –  Aug 04 '16 at 04:12
  • understood, I guess if there was an obvious non ambiguous syntax for this type of tests it would have been adopted. – Julien Aug 04 '16 at 04:14

1 Answers1

0

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.

Óscar López
  • 232,561
  • 37
  • 312
  • 386