save dictionary to a file without brackets.

Dave Angel d at davea.name
Thu Aug 9 17:47:45 EDT 2012


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




More information about the Python-list mailing list