[Tutor] how to iterate through a dictionary and assign list values?

Jared Nielsen nielsen.jared at gmail.com
Thu Dec 5 05:13:12 CET 2013


I want to create a dictionary, assign it keys, then iterate through a for
loop and assign the dictionary values from a list. I'm trying this, but
it's not working:

dictionary = {"one", "two", "three"}
list = [1,2,3]

for key in dictionary:
    for value in list:
        dictionary[key] = value

I get this error:
TypeError: 'set' object does not support item assignment

What am I doing wrong? Any help is greatly appreciated.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20131204/3a702ae7/attachment.html>


More information about the Tutor mailing list