Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 14331

Python Assigning Dictionary to a List

$
0
0

I do not understand the results of this code:

o = {'x':0, 'y':0}mylist=[]for i in range(6):   m = o   m['x'] = i   m['y'] = i*2   mylist.append(m)print(mylist)

How does mylist end up with 5 identical elements?


Viewing all articles
Browse latest Browse all 14331

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>