1

I have code that relies on python 2 typing feature

result1 = result_or_None (...)
result2 = result_or_None (...)

final = max (result1, result2)

Problem is - python 3 doesn't support "Result string" > None comparison so the code returns run-time exception. Python 2 supports this well. Is there way to implement this idiomatically (e.g. without explicitly enumerating all None cases)?

This also uses idea from functional programming (None as bottom value) - bit disappointing not to see it in python3 (what was the rationale for removing this?)

TheNoobGuy
  • 61
  • 3
  • Why this was done? Because the ordering of `None` compared to other types was *arbitrary*, as was any intra-type ordering. It certainly never was meant to be used as a 'bottom' value. You could use `float('-inf')` to signify a bottom numeric value instead. – Martijn Pieters Dec 05 '16 at 10:12
  • 1
    Your variables are strings and you want to get the first string that is defined, and if both of them are None, then None as a result? `final = result1 or result2`. This will work for any values that are considered truthy. – L3viathan Dec 05 '16 at 10:14
  • Good to know! I guess the `"" > None` worked just 'by chance'. +1 for the `final = result1 or result2`, it seems to be correct idiomatic way to do things. Thanks! – TheNoobGuy Dec 06 '16 at 13:43

0 Answers0