I would use Python dictionaries, where the dictionary keys are the values of column A, and the dictionary values are the built-in Python Set the type by holding the values of column B
def parse_the_file():
lower = str.lower
split = str.split
with open('f.txt') as f:
d = {}
lines = f.read().split('\n')
for A,B in [split(l) for l in lines]:
try:
d[lower(A)].add(B)
except KeyError:
d[lower(A)] = set(B)
for a in d:
print "%s - %s" % (a,",".join(list(d[a])))
if __name__ == "__main__":
parse_the_file()
, A. , B.
:
- try-catch , if\ .
- str , .
- A A
a = lower(A) try catch - , Python, .
:
xxxd - 4
xxxa - 1,3,2
xxxb - 2
xxxc - 3