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 = {}?
if dic: a = min(dic, key=dic.get)None? In your own words: how do you write an empty dictionary?if; you didn't know why theifcondition wasn't working as you expected. It should be clear that there is only one possible point of failure: the condition that you're checking. Therefore, you should phrase the question that way - "why does this condition not check that a dictionary is empty?" or something along those lines. When you think more clearly like that, it also helps you find better Internet search terms.