Is it possible, in python, to update or initialize a dictionary key with a single command? -


For example, say, I want to create a histogram, I like it:
   

> To enter the hit = {} data: If the entry [ "Location"] in the hist: hit [entry ["location"]] + = 1 other: hit [entry ["location"]] = 1

depending on the existence of the probe Is there any way to check existence and start or update based on existing existence?

What you want here is a defaultdict : < To import the default entry hist = defaultdict (int) in data import from pre> : hit [entry ["location"]] = = 1

defaultdict < / Code> Default - Any entry that is not already present in dict, so for ints they start at 0 and you simply add one for each item.

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -