Skip to content
Advertisement

Tag: key

How to add multiple values per key in python dictionary

My program needs to output a list of names with three numbers corresponding to each name however I don’t know how to code this is there a way I could do it as a dictionary such as cat1 = {“james”:6, “bob”:3} but with three values for each key? Answer The value for each key can either be a set (distinct

Is it reasonable to use None as a dictionary key in Python?

None seems to work as a dictionary key, but I am wondering if that will just lead to trouble later. For example, this works: The actual data I am working with is educational standards. Every standard is associated with a content area. Some standards are also associated with content subareas. I would like to make a nested dictionary of the

Dictionary keys match on list; get key/value pair

In python… I have a list of elements ‘my_list’, and a dictionary ‘my_dict’ where some keys match in ‘my_list’. I would like to search the dictionary and retrieve key/value pairs for the keys matching the ‘my_list’ elements. I tried this… But it doesn’t do the job. Answer (I renamed list to my_list and dict to my_dict to avoid the conflict

Advertisement