I have a code:
keys = {'a','e','i','o','u'}
value = [1]
vowels = { key : list(value) for key in keys }
print(vowels)
value.append(2)
print(vowels)
The result of this code:
{'a':[1],'e':[1],'i':[1],'o':[1],'u':[1]}
{'a':[1],'e':[1],'i':[1],'o':[1],'u':[1]}
The following code:
keys = {'a','e','i','o','u'}
value = [1]
vowels = { key : value for key in keys }
print(vowels)
value.append(2)
print(vowels)
gives me another result:
{'a':[1],'e':[1],'i':[1],'o':[1],'u':[1]}
{'a':[1,2],'e':[1,2],'i':[1,2],'o':[1,2],'u':[1,2]}
Why it happens if value
and list(value)
are both give the same list object?