Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python min key

square = {2: 4, 3: 9, -1: 1, -2: 4}

# the smallest key
key1 = min(square)
print("The smallest key:", key1)    # -2

# the key whose value is the smallest
key2 = min(square, key = lambda k: square[k])

print("The key with the smallest value:", key2)    # -1

# getting the smallest value
print("The smallest value:", square[key2])    # 1

#OUTPUT
#The smallest key: -2
#The key with the smallest value: -1
#The smallest value: 1
Source by www.programiz.com #
 
PREVIOUS NEXT
Tagged: #python #min #key
ADD COMMENT
Topic
Name
4+1 =