Looking for a way to put this logic into a list comprehension:
new_bills = []
for bill in bills:
for gnr in bill["gnrs"]:
if timestart <= gnr["date"] <= timeend:
new_bills.append(bill)
break
return new_bills
So, these are two nested dictionaries, and I only want the first instance of "bill" that fits the filter.
I used to have this:
return [bill for bill in bills for gnr in bill["gnrs"] if timestart <= gnr["date"] <= timeend]
However, this duped the bill object for everytime the if clause was met. Is there a way to get a list comprehension to behave like the for loop above? Keep in mind sets are out, as the bill is a dictionary (unhashable).
Edit for duplicate answer popup thing: The Solution turned out to be entirely different.