Lets say I have a data file that has this inside it:
23 33 45
91 81 414
28 0 4
7 9 14
8 9 17
1 1 3
38 19 84
How can I import it into a list so that each individual number it its own item?
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.
You could alternatively use the python builtin functions like open file, split and readlines
Another approach is
But, the output will be a list of strings.
That is the each element in the list will represent one line in the file.
If you use the above code the output will look like
You might want them to convert to either float or int.
you could do that using again numpy’s fromstring module
Notice that, I have used a list comprehension in the above code(which is faster than the conventional python for loop.)