我有一个文件,其中包含以下内容:
IA45,TA43,WB58,AB71 ... etc
我想将这些单词转换为列表,例如:
["IA45","TA43","WB58","AB71" .....]
然后,我想用这个列表一个接一个地取单词并拆分并将第一个字母、第二个字母和数字作为分隔变量。我有:
with open("IRL.txt", "r") as f:
resid_list = [x.split(',') for x in f.readlines()]
for r in resid_list:
chain = list(r)[1]
print chain
res = list(r)[0]
print res
num = list(r)[2:]
num1 = "".join(num)
res_num = res+num1
print res_num+" "+chain
问题出在 for 循环中。当我打印“链”时,它只给了我第二个词,没有别的 ---> TA43
但我想打印 --- A