Skip to content
Advertisement

How to check if a name is in a dictionary when the values are lists of names

I have a list of names, and I am trying to loop through that list and see if a name is a value in the name_types dictionary, and if it is then I want to add the name to a results list with a list of the name types that it belongs to, however, I am not sure about how to do this. Also, I want to store None if it is not a part of any.

JavaScript

I tried something like this, but I got too many values to unpack error:

JavaScript

Advertisement

Answer

Your data and result don’t match (‘c’ is a ‘Protocol’). I’ve removed ‘c’ to match the desired result:

JavaScript

Output:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement