fork download
  1. from collections import OrderedDict
  2.  
  3. in_file = ['main cost : 30', 'additional cost : 5', 'main cost : 40', 'additional cost : 10']
  4. someDict = OrderedDict()
  5.  
  6. for line in in_file:
  7. key,val = line.split(' : ')
  8. num = int(val)
  9. if key not in someDict:
  10. someDict[key] = []
  11.  
  12. someDict[key].append(num)
  13.  
  14. for key in someDict:
  15. print(key)
  16. for value in someDict[key]:
  17. print(value)
Success #stdin #stdout 0.02s 10192KB
stdin
Standard input is empty
stdout
main cost
30
40
additional cost
5
10