0

Is there a cleaner way of writing the following:

(a > b) and (a > c)

The following doesn't work, but this might illustrate the kind of thing I'm looking for:

a > [b, c]

Ben
  • 3
  • 2
  • If you're asking because you're writing many equalities as part of a case/switch, you *might* be looking for the new pattern matching. By grouping your matches you could avoid repeatedly testing for conditions. – 2e0byo Oct 13 '22 at 08:57
  • all([a > x for x in [b,c]]) should do what you want. The all() function returns True if a is bigger than all elements in the list. – Inertial Ignorance Oct 13 '22 at 09:05

2 Answers2

2

One option, use max:

a > max(b, c)
mozway
  • 194,879
  • 13
  • 39
  • 75
phipsgabler
  • 20,535
  • 4
  • 40
  • 60
0

You could write c < a > b, but it's pretty weird-looking. Probably clearer simply with a > b and a > c.

khelwood
  • 55,782
  • 14
  • 81
  • 108
  • ouch! Yes, please don't write that. Pick 1 direction to read your code in and stick to it, but preferably pick left-to-right.... – 2e0byo Oct 13 '22 at 08:55