fork download
  1. import sys
  2.  
  3. input_file = sys.stdin
  4.  
  5. # read list of properties
  6. L = [dict(map(str.strip, line.partition('=')[::2])
  7. for line in section.splitlines() if line.strip())
  8. for section in input_file.read().split(';')]
  9. print L
  10.  
  11. # find all names
  12. names = reduce(lambda x, y: x | y, (d.viewkeys() for d in L))
  13.  
  14. # merge all dictionaries and set missing names to '-'
  15. dd = dict((name, [d.get(name, '-') for d in L]) for name in names)
  16. print dd
Success #stdin #stdout 0.09s 10880KB
stdin
Apple = 1
Pear = 1
Orange = 2
;
Orange = 3
Pear = 1
;
Apple = 1
Pear = 1
Orange = 1
stdout
[{'Orange': '2', 'Pear': '1', 'Apple': '1'}, {'Orange': '3', 'Pear': '1'}, {'Orange': '1', 'Pear': '1', 'Apple': '1'}]
{'Orange': ['2', '3', '1'], 'Pear': ['1', '1', '1'], 'Apple': ['1', '-', '1']}