I have an array of array in python. What is the best way to convert it to an array in python?
for example:
m = [[1,2],[3,4]]
# convert to [1,2,3,4]
I am new in python, so I dont know any solution of it better than writing a loop. Please help.
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
itertools.chainorlist comprehension:For smaller lists
comprehensionis faster, for longer oneschain.from_iterableis more suitable.For understanding the nested comprehension, you can split it across multiple lines and compare it to a regular for loop: