Monday, 15 September 2014

list - python appending a value to a sublist -


I'm running into a problem in my program and I'm not sure what I'm doing wrong to start I made an empty list of lists for example:

  & gt; & Gt; & Gt; Lists = [[]] * 12   

returns:

  & gt; & Gt; & Gt; List [[], [], [], [], [], [], [], [], [], [], [], []]   

though When someone tries to add a value to the novelist of a person, then it adds value to all the succulents. For example:

  & gt; & Gt; & Gt; The lists [2] .append (1)   

returns:

  & gt; & Gt; & Gt; The lists [[1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1]   

Is there a way to add only one single mosaic so that the result is displayed:

  & gt; & Gt; & Gt; List [[], [], [1], [], [], [], [], [], [], [], [], []]    

List objects are changeable, so you are actually creating a list with 12 references to a list . Use the understanding of a list and create 12 different lists:

  In the category for lists [[], (12)]   

Sorry, I did not get the original duplicate of this exact question

No comments:

Post a Comment