I have a dict:
JavaScript
x
3
1
dictionary1 = {100: {num: 1, age: 2, line: 3}}
2
dictionary2 = {90: {num: 1, age: 50, line: 4}}
3
I need to write this data into file line by line in the following format:
JavaScript
1
5
1
# HEADER 100 #
2
1 1 2 3
3
# HEADER 90 #
4
1 1 50 4
5
How to do that using Python?
Advertisement
Answer
JavaScript
1
4
1
for i in dictionary1:
2
print('HEADER ',i)
3
print('1 '+' '.join([str(x) for x in list(dictionary1[i].values())]))
4
You can change dictionary1 to dictionary2 for other values.