Write Python program to demonstrate working of Get next key in Dictionary
Topic: Write Python program to demonstrate working of Get next key in Dictionary
Solution
test_dict = {'gfg' : 1, 'is' : 2, 'best' : 3} print(f"The original dictionary is : {test_dict}") test_key = 'is' temp = list(test_dict) try: res = temp[temp.index(test_key) + 1] except (ValueError, IndexError): res = None print(f"The next key is : {res}")
List all Python Programs