Difference between list() and [] with dictionaries

Sam Tregar sam at tregar.com
Fri May 15 21:17:43 EDT 2009


Hello all.  Can anyone explain why this creates a list containing a
dictionary:

  [{'a': 'b', 'foo': 'bar'}]

But this creates a list of keys of the dictionary:

  list({ "a": "b", "foo": "bar" })

I expected them to be equivalent but clearly they're not!  I'm using Python
2.6.1 if that helps.

-sam
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090515/82dd327e/attachment.html>


More information about the Python-list mailing list