My experience is that if more complexity is introduced to data structure then it is good time to return to the drawing board and rethink your approach.
Why there should be additional complexity? Why this structure is required? Source data is list of dictionaries and result is also list of (more complicated) dictionaries. In order to filter out something from this list you have to iterate anyway. Isin't it possible that it is easier to iterate original list instead of creating more complex structure and iterate over it?
Want to have dictionaries from list which are 'good', where n = 1 and without 'm'? List comprehension should be enough:
Why there should be additional complexity? Why this structure is required? Source data is list of dictionaries and result is also list of (more complicated) dictionaries. In order to filter out something from this list you have to iterate anyway. Isin't it possible that it is easier to iterate original list instead of creating more complex structure and iterate over it?
Want to have dictionaries from list which are 'good', where n = 1 and without 'm'? List comprehension should be enough:
>>> orig = [{'name': 'John', 'm': 'good', 'n': 1}, ... {'name': 'Alina','m': 'good', 'n': 1}, ... {'name': 'Olivia', 'm': 'bad', 'n': 2}, ... {'name': 'Ruby', 'm': 'bad','n': 2}] >>> [{k: v for k, v in row.items() if k != 'm'} for row in orig if row['n'] == 1 and row['m'] == 'good'] [{'name': 'John', 'n': 1}, {'name': 'Alina', 'n': 1}]For me it's strange to name source data as 'result'. It may create confusion and confusion may lead to buggy code.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.