I'm new Python and trying to implement code in a more Pythonic and efficient fashion.
Given a dictionary with numeric keys and values, what is the best way to find the largest key with a non-zero value?
Thanks
dictionarypython
I'm new Python and trying to implement code in a more Pythonic and efficient fashion.
Given a dictionary with numeric keys and values, what is the best way to find the largest key with a non-zero value?
Thanks
Best Answer
Something like this should be reasonably fast:
(removing the
!= 0
will be slightly faster still, but obscures the meaning somewhat.)