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

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -