in python:
dic = {} #start with an empty list
After this line, I did a series of command to add things to the dic
. But there is also a situation where nothing is added. Then, I need to use the value in the dic
.
a = min(dic, key=dic.get)
if there is nothing in the dic
, it will give me an error:
ValueError: min() arg is an empty sequence
I don't need an output for a
if dic
is empty, so I then attempted to use the if statement to get away:
if dic == None:
pass
else:
a = min(dic, key=dic.get)
but this will still give me the same error. Is there a way to skip this line of codea = min(dic, key=dic.get)
when dic = {}
?