Pythonic / itertools way to go through a dict?
Posted
by
dmd
on Stack Overflow
See other posts from Stack Overflow
or by dmd
Published on 2012-11-20T16:36:24Z
Indexed on
2012/11/20
17:00 UTC
Read the original article
Hit count: 355
def reportCSV(t):
ret = ''
for ev in t:
for p in t[ev]:
for w in t[ev][p]:
ret += ','.join((ev, p, w, t[ev][p][w])) + '\n'
return ret
What is a more pythonic way to do this, e.g. using itertools or the like?
In this case I'm just writing it out to a CSV file. t is a dict t[ev] is a dict t[ev][p] is a dict t[ev][p][w] is a float
I'm not sure how I'd use itertools.product in this case.
© Stack Overflow or respective owner