List1=[' list1_1]
List2=[]
Data={https://bbs.csdn.net/topics/}
For the lottery in list1:
Data [' a1]='a1_1'
Data [' a2 ']=lottery
For skin in (' a3_1 ', 'a3_2', 'a3_3) :
Data [' a3]=skin
For type_ in (' a4_1 ', 'a4_2) :
Data [' a4]=type_
Print (data)
List2. Append (data)
Print (' -- -- -- -- -- -- -- - ')
For a in list2:
Print (a)
Input the results:
{' a1: 'a1_1', 'a2' : 'list1_1', 'a3' : 'a3_1', 'a4' : 'a4_1}
{' a1: 'a1_1', 'a2' : 'list1_1', 'a3' : 'a3_1', 'a4' : 'a4_2}
{' a1: 'a1_1', 'a2' : 'list1_1', 'a3' : 'a3_2', 'a4' : 'a4_1}
{' a1: 'a1_1', 'a2' : 'list1_1', 'a3' : 'a3_2', 'a4' : 'a4_2}
{' a1: 'a1_1', 'a2' : 'list1_1', 'a3' : 'a3_3', 'a4' : 'a4_1}
{' a1: 'a1_1', 'a2' : 'list1_1', 'a3' : 'a3_3', 'a4' : 'a4_2}
-- -- -- -- -- -- -- --
{' a1: 'a1_1', 'a2' : 'list1_1', 'a3' : 'a3_3', 'a4' : 'a4_2}
{' a1: 'a1_1', 'a2' : 'list1_1', 'a3' : 'a3_3', 'a4' : 'a4_2}
{' a1: 'a1_1', 'a2' : 'list1_1', 'a3' : 'a3_3', 'a4' : 'a4_2}
{' a1: 'a1_1', 'a2' : 'list1_1', 'a3' : 'a3_3', 'a4' : 'a4_2}
{' a1: 'a1_1', 'a2' : 'list1_1', 'a3' : 'a3_3', 'a4' : 'a4_2}
{' a1: 'a1_1', 'a2' : 'list1_1', 'a3' : 'a3_3', 'a4' : 'a4_2}
List2 why only preserved the last 1 row
CodePudding user response:
List1=[' list1_1]
List2=[]
For the lottery in list1:
Data={} https://bbs.csdn.net/topics/# cycle when empty, this is a new variable
Data [' a1]='a1_1'
Data [' a2 ']=lottery
For skin in (' a3_1 ', 'a3_2', 'a3_3) :
Data [' a3]=skin
For type_ in (' a4_1 ', 'a4_2) :
Data [' a4]=type_
Print (data)
List2. Append (data)
Print (' -- -- -- -- -- -- -- - ')
For a in list2:
print(a)
CodePudding user response:
I can't, the same effect
CodePudding user response:
The
0 f chenjun1989 reference response: list1=[' list1_1] List2=[] Data={https://bbs.csdn.net/topics/} For the lottery in list1: Data [' a1]='a1_1' Data [' a2 ']=lottery For skin in (' a3_1 ', 'a3_2', 'a3_3) : Data [' a3]=skin For type_ in (' a4_1 ', 'a4_2) : Data [' a4]=type_ Print (data) List2. Append (data) Print (' -- -- -- -- -- -- -- - ') For a in list2: Print (a) Input the results: {' a1: 'a1_1', 'a2' : 'list1_1', 'a3' : 'a3_1', 'a4' : 'a4_1} {' a1: 'a1_1', 'a2' : 'list1_1', 'a3' : 'a3_1', 'a4' : 'a4_2} {' a1: 'a1_1', 'a2' : 'list1_1', 'a3' : 'a3_2', 'a4' : 'a4_1} {' a1: 'a1_1', 'a2' : 'list1_1', 'a3' : 'a3_2', 'a4' : 'a4_2} {' a1: 'a1_1', 'a2' : 'list1_1', 'a3' : 'a3_3', 'a4' : 'a4_1} {' a1: 'a1_1', 'a2' : 'list1_1', 'a3' : 'a3_3', 'a4' : 'a4_2} -- -- -- -- -- -- -- -- {' a1: 'a1_1', 'a2' : 'list1_1', 'a3' : 'a3_3', 'a4' : 'a4_2} {' a1: 'a1_1', 'a2' : 'list1_1', 'a3' : 'a3_3', 'a4' : 'a4_2} {' a1: 'a1_1', 'a2' : 'list1_1', 'a3' : 'a3_3', 'a4' : 'a4_2} {' a1: 'a1_1', 'a2' : 'list1_1', 'a3' : 'a3_3', 'a4' : 'a4_2} {' a1: 'a1_1', 'a2' : 'list1_1', 'a3' : 'a3_3', 'a4' : 'a4_2} {' a1: 'a1_1', 'a2' : 'list1_1', 'a3' : 'a3_3', 'a4' : 'a4_2} List2 why only preserved the last 1 row data List is not only save the value of the last line! You list only preserved the six data object, or an object that holds the six times! You kept in the loop, to assignment of the data, the data of your list2 also in change, that is to say, you are the first data, append entered in your cycle, also is changing, finally, what is the value of your data, what is 6 in your list! CodePudding user response:
List1=[' list1_1] List2=[] Data={https://bbs.csdn.net/topics/} Data1={} Data2={} Data3={} For the lottery in list1: Data [' a1]='a1_1' Data [' a2 ']=lottery For skin in (' a3_1 ', 'a3_2', 'a3_3) : Data1={} Data1=[' a3] skin For type_ in (' a4_1 ', 'a4_2) : Data2={} Data2=[' a4] type_ Data3={} Data3. Update (data) Data3. Update (data1) Data3. Update (data2) Print (data3) List2. Append (data3) Print (' -- -- -- -- -- -- -- - ') For a in list2: print(a) CodePudding user response:
The final indentation line