Oct-03-2017, 09:57 PM
Why do you keep bringing up the csv module? You're not working with a csv file, so the module does nothing for you. Just because you want to print some data to the screen with commas added?
You could do this in a few ways. Right now, what you have is right, except you want all the items on the same line. So, this would work:
You could do this in a few ways. Right now, what you have is right, except you want all the items on the same line. So, this would work:
for dicts in data: first = True for key in dicts: if not first: print(", ", end="") first = False print(dicts[key], end="") print()Or, if you want to be clever, you can use the str.join() method and the dict.values() method to turn all that into just one line:
>>> items = {"foo": "bar", "spam": "eggs"} >>> print(", ".join(items.values())) eggs, bar