Python 它们是不变的 d = [] ... d.append({self.start_x,self.start_y}) ... #retrieving last click print d[-1] # adding other things to the 'las

Python 它们是不变的 d = [] ... d.append({self.start_x,self.start_y}) ... #retrieving last click print d[-1] # adding other things to the 'las,python,list,dictionary,Python,List,Dictionary,它们是不变的 d = [] ... d.append({self.start_x,self.start_y}) ... #retrieving last click print d[-1] # adding other things to the 'last click dictionary' d[-1]['type'] = 'foobar' 我认为这对于第一次使用的用户来说是很好的(干得好!),但是在将来,如果您致力于最小化提交的代码量,您可能会得到更好的结果。我希望这可以简化为一个函数发布

它们是不变的

d = []
...
d.append({self.start_x,self.start_y})
...
#retrieving last click
print d[-1]
# adding other things to the 'last click dictionary'
d[-1]['type'] = 'foobar'

我认为这对于第一次使用的用户来说是很好的(干得好!),但是在将来,如果您致力于最小化提交的代码量,您可能会得到更好的结果。我希望这可以简化为一个函数发布,在这种情况下,它甚至可能是一个重复的函数。我认为这对于第一次使用它的用户来说是很好的(干得好!),但是在将来,如果您致力于最小化提交的代码量,您可能会得到更好的结果。我希望这可以缩减为一个函数,在这种情况下,它甚至可能是一个重复的
def on_button_press(self, event):
    # save mouse drag start position
    self.start_x = event.x
    self.start_y = event.y
    d["top_left_coords"] = [self.start_x, self.start_y]
d["top_left_coords"] = [self.start_x, self.start_y]
d = []
...
d.append({self.start_x,self.start_y})
...
#retrieving last click
print d[-1]
# adding other things to the 'last click dictionary'
d[-1]['type'] = 'foobar'