Do you think (key, value) in dictionary.viewitems() is horrific? It seems to me that it's pretty close to ideal. The only improvement would be if I'd been able to just write (key, value) in dictionary, on the principle that a dictionary is mathematically speaking a restricted form of relation and a relation is a subset of the set of possible ordered pairs. Sadly, in dictionary was already used for something else.
It doesn't read naturally to me,and tell me what it's doing. I'd rather end up with code like: if dictionary.itemequals(key,value): but that may just be my lack of familiary with Python showing. If the former code is idiomatic Python then go for it.
My brain clicked this morning, and suddenly the viewitems seems much more natural. I was clearly too tired to be looking at code when I commented last night.
On the other hand, I freely concede the horrificness of the NaN approach! But then, I never intended to put that one in actual code, only to post it on the Internet and marvel at how horrible it was :-)
(key, value) in dictionary.viewitems()is horrific? It seems to me that it's pretty close to ideal. The only improvement would be if I'd been able to just write(key, value) in dictionary, on the principle that a dictionary is mathematically speaking a restricted form of relation and a relation is a subset of the set of possible ordered pairs. Sadly,in dictionarywas already used for something else.if dictionary.itemequals(key,value):
but that may just be my lack of familiary with Python showing. If the former code is idiomatic Python then go for it.