list in python behaviour -
I have a list that lists my_list mylist = [[]] * 5
Now I want to add an integer to 4 from the third list in my_list
my_list [2] .append (4)
When I print My_list, I see that integer 4 has been added to each list in my_list.
& gt; & Gt; & Gt; My_list = [[]] * 5
& gt; & Gt; & Gt; My_list [2] .append (4)
& gt; & Gt; & Gt; My_list
[[4], [4], [4], [4], [4]]
there is one Just the way to add 4 to the third list?
Expected:
[[], [], [4], [], []]
Actual:
[[4] ], [4], [4], [4], [4]]
Find Answers
my_list = [[]] I should do the
move in xrange (5)]
Comments
Post a Comment