dictionary changed size during iteration after pop function
cars = {
"brand": "Tesla",
"model": "Model S Plaid",
"year": 2021
}
for x in cars.keys():
cars["color"] = "white"
print(x)
dictionary changed size during iteration after pop function
cars = {
"brand": "Tesla",
"model": "Model S Plaid",
"year": 2021
}
for x in cars.keys():
cars["color"] = "white"
print(x)
dictionary changed size during iteration after pop function
import copy
cars = {
"brand": "Tesla",
"model": "Model S Plaid",
"year": 2021,
}
#creating a shallow copy
cars_copy = copy.copy(cars)
for x in cars_copy.keys():
cars["color"] = "black"
print(cars)
print(cars_copy)
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us