code not working
Hello I am continuing to learn with "crash course in python" I am at the section on dictionary and how to put dictionary into list, and iterate through them. I started by creating a list and dictionary, and wrote a code to insert the dictionary in the list, worked fine. Then I tried to modify the value of one key, in some of the dictionary. dic = { 'a' : 1, 'b' : 2, 'c' : 4, 'd' : 5, } list1 = ['f','e','c','n'] print(list1) print(len(list1)) x = 0 while x < 7: if x <= len(list1) - 1: list1[x] = dic x += 1 else: list1.append('vv') x +=1 print(list1) for dic in list1[:2]: dic['c'] = 'wistiti' print(list1) I wrote it exactly like in the book but does not work. With this version the key 'c' is changed to the specify value, in EVERY dictionary in my list. And if I write list1[1] list1[:] I get this error message File "c:....../Crash course/dictionaryloop.py", line 21, in <module> dic['c'] = 'wistiti' TypeError: 'str' object does not support item assignment Any input on what I am doing wrong?