def parse_pairs data keys values for in data splitlines if in key valu

1
2
3
4
5
6
7
8
9
def parse_pairs(data):
keys = {}
values = {}
for x in data.splitlines():
if ':' in x:
key, value = x.rstrip('\r\n').split(':', 1)
keys.setdefault(key, []).append(value)
values.setdefault(value, []).append(key)
return {'keys': keys, 'values': values}