Sorry, i'm a bit new to python and any help is appreciated.
I'm trying to assign 2 values to a dictionary key using a variable that is given a value when prompted. I keep getting this error message:
Traceback (most recent call last):
File "C:\Users\Fader\Desktop\List creator.py", line 41, in <module>
myLists[key].append(edit)
AttributeError: 'str' object has no attribute 'append'
This is what I have so far:
print (list(myLists.keys()))
key=input("What List would you like edit?")
myLists.setdefault(key, [])
edit=input("What would you like to add?")
myLists[key].append(edit)
Im trying to prompt for a key. Set that key as the default and then prompt for an edit and append the edit to the specified key.
I think instead of default
you mean initial
value.
Please change the third line to this, and check if this is what you meant:
myLists[key] = []
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments