I am trying to iterate and separate nested lists. My data input is currently something like this. .
mainlist = [['1', 'HiII', '0', '1407', '0', 'Commander', '11.06.2018'],
['2', 'wEEDzy', '0', '1184', '0', 'Private', '24.03.2021']]
My goal is to use a for
loop to separate each list into its own list, then pull specific variables from that list, then output it to a text file. I want to pull only values 1, 3, & 5 from each list.
Now that you know my objective, I am trying to use a for
loop to separate each list into its own variable and make that list only those 3 values that are needed.
This is the desired output (each assigned to a variable, then added to a .txt value)
['HiII', '1407', 'Commander']
['wEEDzy','1184', 'Private']
My current code is this: , which separates a list and then adds only the things I want from the list to it.
member1 = list(mainlist[0])
templist = []
templist.append(member1[1])
templist.append(member1[3])
templist.append(member1[5])
What I can't figure out is how to do this for each one for x amount of members so I don't copy and paste it everytime. Can anyone help?