How to search for the highest key from Python dictionary?

PythonServer Side ProgrammingProgramming

Python's built-in dictionary class has keys() method which returns list of all key components in each key-value pair. The built-in function max() gives highest key from the list

>>> dct={1:45,2:76,3:12,4:55,5:33}
>>> klist=dct.keys()
>>> klist
dict_keys([1, 2, 3, 4, 5])
>>> max(klist)
5
raja
Published on 27-Feb-2018 19:59:52
Advertisements