Search
 
SCRIPT & CODE EXAMPLE
 

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
Comment

PREVIOUS NEXT
Code Example
Python :: pylab plotting data 
Python :: transform image to rgb python 
Python :: torch print full tensor 
Python :: python find first occurrence in list 
Python :: django login url 
Python :: post list python 
Python :: Converting objects into integers in python 
Python :: How to take multiple input form python 
Python :: simple heatmap 
Python :: import module python same directory 
Python :: python A string float numeral into integer 
Python :: obtain files python 
Python :: pandas series 
Python :: how to add a column with more rows to a dataframe 
Python :: list in one line of text in python 
Python :: To create a SparkSession 
Python :: tkinter mainloop 
Python :: how to give float till 5 decimal places 
Python :: align a text python 
Python :: python recognize every white color 
Python :: pandas if value present in df index 
Python :: dtype array 
Python :: len of iterator python 
Python :: error: not well-formed (invalid token) 
Python :: how to set python path in mac 
Python :: codechef solution 
Python :: np.array([(1,2),(3,4)],dtype 
Python :: django model different schema 
Python :: python random uuid 
Python :: python portfolio projects 
ADD CONTENT
Topic
Content
Source link
Name
7+4 =