I have a list as follows:
list1 = [['abc',{2:1,10:8,7:4,3:4,5:6}],['xyz',{3:8,5:7,2:4,1:9}],.......]]
I want to write the list in a o/p file in the below mentioned format where all the dictionary items are sorted in increasing order based on the key values.
'abc' 2:1 3:4 5:6 7:4 10:8
'xyz' 1:9 2:4 3:8 5:7
I have written the code as follows:
for k, v in list1:
outputfile.write(k + ' ' + ' '.join('{}:{}'.format(key, val) for key, val in v.items()) + '\n')
But I am not able to get the desired result. Please help me with a solution for it.