4

Can anyone show me how to slice the structure below:

[[1, A], [2, B], [3,C]]

Into two separate lists:

[1, 2, 3]
[A, B, C]

I can obviously do this using code, but wondered if Python was able to do it natively?

1 Answer 1

13
my_list = [[1, A], [2, B], [3, C]]
a, b = zip(*my_list)

Note that a and b will end up being tuples.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you Sven! This is perfect.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.