Skip to main content

Python code to print the key values in dictionary-like maximum, minimum, specific record

Here is complete running code for python which gives output for printing maximum, minimum from key elements, and associated value. Print complete dictionary. Print specific number record.

thisdict = {
  "1": "C language",
  "2": "Java Language",
  "4": "Python Language",
  "3": "C++",
}
maxNumber= max(thisdict,key=thisdict.get)
print(maxNumber)
print('\n\n')
minNumber = min(thisdict,key=thisdict.get)
print(minNumber)
print("\n\n")

# Print key-value pairs in dictionary whose key is maxNumber
for key, value in thisdict.items():
    if key == maxNumber:
        print(key, '::', value)
print('\n\n')

#print complete dictionary
print(thisdict)
print('\n\n')
#print 2nd record from dictionary

n=2
for index, (key, value) in enumerate(thisdict.items()):
    if index == n:
        print(key, '::', value)
        break

Output

4



1



4 :: Python Language



{'1': 'C language', '2': 'Java Language', '4': 'Python Language', '3': 'C++'}



4 :: Python Language

To python code online refer free online compiler.