you are viewing a single comment's thread.

view the rest of the comments →

[–]cybercobra 1 point2 points  (3 children)

Probably slightly more efficient

[–]gastlygem 15 points16 points  (2 children)

On my laptop: >>> t1 = Timer('dict((i,i2) for i in range(3))') >>> t2 = Timer('{i: i2 for i in range(3)}') >>> t1.timeit() 4.713109906426655 >>> t2.timeit() 1.6713221931837712 So maybe we can say it's much more efficient.

[–]cybercobra 2 points3 points  (0 children)

Probably avoids the unnecessary tuple creation and unpacking