可以字典套字典来用
book = {
'a':{'A' : 1},
'b':{'B' : 0},
'c':{'C' : 1},
'd':{'D' : 0}
}
bookname = 'd'
bookauthor = 'D'
bookpay = 1
print book
# 先判是否有这本书
if bookname in book:
# 判断是否是该作者的
if bookauthor in book[bookname]:
# 再判断是否付费 1付费,0未付费
if book[bookname][bookauthor] == 0:
if bookpay == 1:
book[bookname][bookauthor] = 1
else: # 不是该作者
book[bookname][bookauthor] = bookpay
else: # 没有这本书
book[bookname][bookauthor] = bookpay
print book
# 总体来说就是这么个意思,可以参考修改自己的代码
# 自己动手丰衣足食~
#!/usr/bin/python3
re = (['JOINT\n',''], ['LOAD',''], ['X=',','], ['Y=',','], ['Z=',','], [" ",""])
fin = open("a.txt", "rt").read()
for r in re:
fin = fin.replace(r[0],r[1])
open("b.txt", "wt").write(fin)