save dictionary to a file without brackets.
88888 Dihedral
dihedral88888 at googlemail.com
Fri Aug 10 13:46:09 EDT 2012
Dave Angel於 2012年8月10日星期五UTC+8上午5時47分45秒寫道:
> On 08/09/2012 05:34 PM, 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).
>
>
>
> Sure, that's why
>
>
>
> for key in dict:
>
> print key[0], key[1], dict[key]
>
>
>
> is probably slower than
>
>
>
> for (edge1, edge2), cost in d.iteritems(): # or .items()
>
> print edge1, edge2, cost
>
>
>
>
>
> So, the latter is both faster and easier to read. Why are you arguing against it?
>
>
>
> Also, please stop top-posting. It's impolite here, and makes it much harder to figure out who is saying what, in what order.
>
>
>
>
>
>
>
> --
>
>
>
> DaveA
OK, lets estimate the hash colision rate first.
For those items hashed to the same key, I'll store a sorted list with a
known lenth m to be accessed in O(LOG(M)).
Of couse another hash can be attatched.
More information about the Python-list
mailing list