Andrew Cooper於 2012年8月10日星期五UTC+8上午6時03分26秒寫道: > On 09/08/2012 22:34, Roman Vashkevich wrote: > > > Actually, they are different. > > > Put a dict.{iter}items() in an O(k^N) algorithm and make it a hundred > > thousand entries, and you will feel the difference. > > > Dict uses hashing to get a value from the dict and this is why it's O(1). > > > > > > > Sligtly off topic, but looking up a value in a dictionary is actually > > O(n) for all other entries in the dict which suffer a hash collision > > with the searched entry. > > > > True, a sensible choice of hash function will reduce n to 1 in common > > cases, but it becomes an important consideration for larger datasets. > > > > ~Andrew
This is the classical problem of storing the hash collision items one by one. Those items should be stored by some order. -- http://mail.python.org/mailman/listinfo/python-list