I thought that dictionaries and lists were mutable in Python. What explains this behavior?
#!/usr/bin/python3
def change_list(l):
l = ['changed!']
def change_dict(d):
d = {'changed!'}
mydict = {'bob': ['blah', 5], 'asdf' : 'asdf'}
change_dict(mydict)
print(mydict)
mylist = ['hello', 'foo', 'bar']
change_list(mylist)
print(mylist)
Output:
$ python3 test3.py
{'asdf': 'asdf', 'bob': ['blah', 5]}
['hello', 'foo', 'bar']
Expected output:
$ python3 test3.py
{'changed!'}
['changed!']