书中代码有一处是这样写的

for k,v in self.ladders.items():
            self.ladders[v] = k
            print('ladders info:')
            print(self.ladders)
            print('dice ranges:')
            print(self.dices)
        self.pos = 1

本质上没有任何问题,但是我是python3.5的版本,字典这一块就用不了,所以会出现如下错误:

for k,v in self.ladders.items():

RuntimeError: dictionary changed size during iteration

所以代码进行如下改变就好用了。

for k,v in list(self.ladders.items()):
            self.ladders[v] = k
            print('ladders info:')
            print(self.ladders)
            print('dice ranges:')
            print(self.dices)
        self.pos = 1

 

posted on 2018-05-30 15:11  Fiona_Y  阅读(84)  评论(0编辑  收藏  举报