i'm trying to get a formatted string with all attributes from all dictionaries in a list using list comprehension
results = [{'TTL': '1643410114', 'customer': '1212', 'date': '2021-01-28', 'file': 'file.gz'}] print("***** SEARCH RESULTS ***** ".join([ f"{key}: {value} " for key, value in obj.items() for obj in results ]))
and I got NameError: name 'obj' is not defined, I tried some combinations without success, how can I archieve this?
NameError: name 'obj' is not defined
You have your inline for-loops in the wrong order:
>>> [ "{}: {} ".format(key, value) for obj in results for key, value in obj.items() ] ['customer: 1212 ', 'date: 2021-01-28 ', 'file: file.gz ', 'TTL: 1643410114 ']
1.4m articles
1.4m replys
5 comments
57.0k users