I’ve got a few lines of code for iterating over a dict within a list and I’m looking to shorten it. It works perfectly as is, but seems like too much code and I’m trying to get a feel for how to keep code efficient in Python (or in general really).
for d in dev['devices']:
if d['name'] == devName:
devFound = True
break
The structure of ‘dev’ is a bit confusing but for the data I care about:
dev (dict) > devices (list) > 0-n (dict)
the value ‘name’ is a key within the inner numbered dict (varies depending on the search value elsewhere) which needs to be checked against a user input (devName)
Any input much appreciated
Basically the same, only rewritten with some built-in function and a generator: