The defined function will return the altered dictionary. The parameter 'teams' is a dictionary and the parameter 'driver' is a string. The key of 'teams' is the driver and its value is the other team member. So I am trying to swap the 'driver' from the input parameter and the other team member:
def switch(teams, driver):
temp = teams[driver]
switch[temp] = driver
del switch[driver]
return teams
print(switch({'Jack':'Jill', 'Romeo':'Juliet', 'Drake':'Josh'}, 'Drake'))
Why am I getting the following error message? Where in the code am I going wrong?
switch[temp] = driver TypeError: 'function' object does not support item assignment
To stay consistent with your method:
def switch(teams, driver):
temp = teams[driver]
teams[temp] = driver
del teams[driver]
return teams
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.