Answers for "python loop through dictionary with condition"

24

python loop through dictionary

dictionary = {52:"E",126:"A",134:"B",188:"C",189:"D"}
for key, value in dictionary.items():
	print(key)
	print(value)
Posted by: Guest on July-02-2020
0

iterate through dict with condition

>>> categories=   [{ 'Id': 1350, 'hasCategory': True},
               { 'Id': 113563, 'hasCategory': True},
               { 'Id': 328422, 'hasCategory': False}]
>>> [i['Id'] for i in categories if i['hasCategory'] == True]
[1350, 113563]
Posted by: Guest on November-13-2021

Code answers related to "python loop through dictionary with condition"

Python Answers by Framework

Browse Popular Code Answers by Language