I am learning python and would like to know if there is a pythonic way of doing this. Of course I can do an
if len(a) > len(b) :
(x,y) = (b,a)
and so on. But this seems a bit verbose. Is there a more beautiful way to do this in python?
Sorting seems a bit overkill. You can do it in one line just with if
.
x,y = (a,b) if len(a) < len(b) else (b,a)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With