def read_database(file):
d={}
file=open('database.txt')
for line in file:
(key,val)=line.split(';')
d[key]=val
return d
print(read_database('database.txt'))
此代码返回
{'GGGGGCTACAAACTCTCAGG': 'High blood pressure,Osteoarthritis,liver disease\n', 'AGCTCAGTATAAAATCTAAG': 'Diabetes,lung disease\n', 'AAAAATCTATGCTCACCGAC': 'Breathing problems\n',...}
但我想摆脱" \ n"在每一行的末尾。任何想法如何做到这一点?
答案 0 :(得分:0)
def read_database(filename):
d = {}
with open(filename) as f:
for line in f.readlines():
key, value = line.split(';')
d[key] = value
return d
print(read_database('database.txt'))
我解决了一些其他问题,而在它