Reputation: 1529
I have a dictionary, and have assigned multiple values to it like so -
d = {"names[]": ["System/CPU/User/percent", "System/CPU/System/percent"], "values[]": "average_value"}
I want the output to look like this -
names[]: System/CPU/User/percent
names[]: System/CPU/System/percent
values[]: average_value
How can I accomplish this? The different for loop iterations that I have tried are not correctly parsing through the list.
Thanks.
Upvotes: 0
Views: 76
Reputation: 14847
In [2]: for k, v in d.iteritems():
...: if isinstance(v, list):
...: for s in v:
...: print '{}: {}'.format(k, s)
...: else:
...: print '{}: {}'.format(k, v)
...:
values[]: average_value
names[]: System/CPU/User/percent
names[]: System/CPU/System/percent
Upvotes: 5