If I have, for example, a list of tuples such as
a = [(1,2)] * 4
how would I create a list of the first element of each tuple? That is, [1, 1, 1, 1].
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Use a list comprehension:
You can also unpack the tuple:
If you want to get fancy, combine
mapandoperator.itemgetter. In python 3, you’ll have to wrap the construct inlistto get a list instead of an iterable: