在使用iteritems()遍历字典时,有没有一种简单的方法来检测最后一次迭代
发布于 2011-05-23 04:18:48
正如其他人所说的,字典没有定义的顺序,所以很难想象为什么需要它,但这里就是它
last = None
for current in your_dict.iteritems():
  if last is not None:
    # process last
  last = current
# now last contains the last thing in dict.iteritems()
if last is not None: # this could happen if the dict was empty
  # process the last itemhttps://stackoverflow.com/questions/6090417
复制相似问题