-1

If I have different lists such as :

['D1', 'D2', 'D3'] ['S1', 'S2', 'S3'] ['X1', 'X2', 'X3']

How can I create a list of lists that groups elements from different lists according to their index ? I want to obtain the following output :

[['D1', 'S1', 'X1'] ['D2', 'S2', 'X2'] ['D3', 'S3', 'X3']
Raghad
  • 53
  • 5
  • If you have a *numpy array* however, see [`numpy.transpose`](https://numpy.org/doc/stable/reference/generated/numpy.transpose.html). – SuperStormer May 08 '22 at 01:45
  • `original = [['D1', 'D2', 'D3'], ['S1', 'S2', 'S3'], ['X1', 'X2', 'X3']]` then `new = np.array(original).T.tolist()` – richardec May 08 '22 at 01:45
  • A relatively well known list "transpose" `list(zip(['D1', 'D2', 'D3'], ['S1', 'S2', 'S3'], ['X1', 'X2', 'X3']))` – hpaulj May 08 '22 at 03:00

0 Answers0