-, mydict , #, ( ), , , #. .
python3, python2, mydict.items() mydict.iteritems() -
mydict = dict()
with open("sample.csv") as inputs:
for line in inputs:
if line.startswith("#"):
key = line.strip()[1:]
mydict.setdefault(key,list())
else:
mydict[key].append(line.strip())
result = dict()
for key, vlist in mydict.items():
result[key] = "".join(vlist)
print(result)
:
{'labelA': 'thereissomethinghere', 'label_Bbb': 'hereaswell'}