You are doing it wrong.
The dict() constructor does not accept a list of elements (and especially a list containing one list of elements), it accepts the iterability of iterations of 2 elements. Therefore, if you change your code:
myList = [] myList.append(["mykey1", "myvalue1"]) myList.append(["mykey2", "myvalue2"]) myDict = dict(myList)
Then you get what you expect:
>>> myDict {'mykey2': 'myvalue2', 'mykey1': 'myvalue1'}
The reason this works:
myDict = dict([['prop1', 'prop2']]) {'prop1': 'prop2'}
This is because he interprets it as a list containing one item, which is a list that contains two items.
Essentially, the dict constructor takes its first argument and executes code similar to this:
for key, value in myList: print key, "=", value
Daniel Pryden
source share