<html><head><style type='text/css'>p { margin: 0; }</style></head><body><div style='font-family: Arial; font-size: 12pt; color: #000000'>Hi all,<br>&nbsp;&nbsp; Sorry to bug everybody, but I'm having some trouble with a somewhat tricky class I'm trying to make.&nbsp; I have a class that inherits from collections.OrderedDict, in an effort to create an ordered dictionary with some extra functions.&nbsp; Now what I'd like to do is to change the iteration so that when you iterate over it, it iterates over values instead of keys.&nbsp; This is turning out to be harder than I thought.&nbsp; First, I tried this:<br><br>class od2(collections.OrderedDict):<br>&nbsp;&nbsp;&nbsp; def __iter__(self):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return iter(self.values())<br><br>Now the code I'm running creates a dict and tries to do a .copy on it, but I'd expect the problem to come up with most kind of dictionary access.&nbsp; The problem is that it goes into an infinite recursion with messages like this<br><br>File "...", line 57, in __iter__<br>&nbsp; return iter(self.values())<br>File ".../python/2.7.1/linux64/lib/python2.7/_abcoll.py" line 372 in values<br>&nbsp; return [self[key] for key in self]<br><br>It looks like the values() function uses the iterator to generate the values.&nbsp; OK, so maybe I'll try this:<br><br>class od2(collections.OrderedDict):<br>&nbsp;&nbsp;&nbsp; def __iter__(self):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; values = [self[key] for key in self.keys()]<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return iter(values)<br><br>that gives me messages like this:<br><br>File "...", line 56, in __iter__<br>&nbsp; values = [self[key] for key in self.keys()]<br>File ".../python/2.7.1/linux64/lib/python2.7/_abcoll.py" line 366 in keys<br>&nbsp; return list(self)<br><br>and list() uses the iterator.&nbsp; Gah.&nbsp; So I'm out of ideas here, even if I dig into OrderedDict and find some way to pull the keys out, I'll probably have to rewrite a bunch of access functions for it to still work like a dictionary.&nbsp; Am I just tilting at windmills, or is doing something like this actually possible?&nbsp; Or am I just being dense, and there's a super obvious way to do this? Thanks for any help!<br><br>(Oh, and forgive me if there's a known fix for this, googling for anything along these lines just sent me to tons of tutorials about using the .values() function.&nbsp; No help there.)<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ------- Corey<br></div></body></html>