I have a long list of sublists looking like this: [[A,B,C,D],[A,B,C,D],[A,B,C,D]].
What I want to do is Join all the A lists together, all the B lists together, etc...
I have found a way of doing this but it is not very elegant, and not elegant at all when the list gets very long. So I was wondering if there was a practical way of solving this.
I have tried indexing through the list. And this works fine but as I mentioned above my solution (shown below) is not good for long lists. I have tried indexing with the mod (%) operator, but this won't work since I have index 2 and 4 in my list which will yield 0 for bot at 4 e.g.
self.Input_full = [[listA],[listB],[listC],[listD],[listA],etc...]
for sublist in self.Input_full:
for list in sublist:
if sublist.index(list) == 0 or sublist.index(list) == 4 or sublist.index(list) == 8:
self.X_sent.append(list)
elif sublist.index(list) == 1 or sublist.index(list) == 5 or sublist.index(list) == 9:
self.Y_sent.append(list)
elif sublist.index(list) == 2 or sublist.index(list) == 6 or sublist.index(list) == 10:
self.Ang_sent.append(list)
else:
self.T_sent.append(list)
The desired output is to get One list with all the lists A, one with all the lists B, etc...