On 9/4/07, Georg Brandl <[EMAIL PROTECTED]> wrote: > Noam Raphael schrieb: > > Just out of curiousity - do you remember these reasons? I just have > > the feeling that back then, iterations were less common, since you > > couldn't iterate over dicts without creating new lists, and you didn't > > have list comprehensions and generators. You couldn't write an > > expression such as > > dict((x, y) for y, x in d) > > to quickly get the inverse permutation, so the relative ugliness of > > dict((x, y) for y, x in d.items()) > > was not considered. > > Well, what about dict((x, d[x]) for x in d) ? Doesn't strike me as ugly...
It doesn't strike me as ugly, it just strikes me as slow. In C++, a std::map::iterator will give you std::pair<KeyT, ValueT>, and I've often wanted such a construction in Python. Right now to get a similar thing, you pay something like O(n log n) (assuming d[x] is O(log n)) instead of O(n). Not to mention that we know that d[x] is pretty expensive these days on common lookups, since we're not dropping into the fast lookdict_string anymore. -- Nick _______________________________________________ Python-3000 mailing list [email protected] http://mail.python.org/mailman/listinfo/python-3000 Unsubscribe: http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com
