Iterate a list in a dictionary, if the list exists in the dictionary. In Python

Asked
Active3 hr before
Viewed126 times

2 Answers

pythoniterateexistsdictionary
90%

Meta Stack Overflow , Stack Overflow help chat ,Stack Overflow en español,Stack Overflow на русском

Example_snippet/controller/utility/_python.js/ if 'some_list' in some_dict.ke. . .
if 'some_list' in some_dict.keys():
   for value in some_dict['some_list']:
   #Run some code using value
load more v
88%

So the question is, how to check if any element in my_list also appears in a dictionary as a key in my_dict,,If you need to loop through all the elements that are used as the dictionary key, we replace the if statement with the loop as shown here:,In this article, we show two ways to check if any element in the list of strings is also used as a key in a dictionary

Example_snippet/controller/utility/_iterate.js/ my_list=["A", "B", "C", "D"] m. . .
my_list = ["A", "B", "C", "D"]
my_dict = {
   "ABC": "10",
   "MM": "3",
   "A": "8"
}
load more v