Mar-19-2018, 08:46 PM
What about a dict, with the value being a list of every occurrence?
>>> data = '''a : one ... b : two ... c : three ... d : four ... a : five ... b : six ... c : seven ... d : eight ... e : nine'''.split('\n') >>> data ['a : one', ' b : two', ' c : three', ' d : four', ' a : five', ' b : six', ' c : seven', ' d : eight', ' e : nine'] >>> parsed = {} >>> for item in data: ... key, value = item.split(':') ... key = key.strip() ... value = value.strip() ... if key not in parsed: ... parsed[key] = [] ... parsed[key].append(value) ... >>> parsed {'c': ['three', 'seven'], 'd': ['four', 'eight'], 'b': ['two', 'six'], 'a': ['one', 'five'], 'e': ['nine']}