> Does anyone have an easier/faster/better way of popping from the middle > of a deque than this? > > class mydeque(deque): > def popmiddle(self, pos): > self.rotate(-pos) > ret = self.popleft() > self.rotate(pos) > return ret
My first thought would just be to use indexing: def popmiddle(self, pos): ret = self[pos] del(self[pos]) return ret It seems to work with my Python2.4 here. If you're interested in efficiency, I'll leave their comparison as an exercise to the reader... :) -tkc -- http://mail.python.org/mailman/listinfo/python-list