Reputation: 191
I am trying to read a matrix in python, using the following code:
rows = int(input())
columns = int(input())
final = [''] * rows
for i in range(len(final)):
final[i] = list(input())
This is giving me a time limit in the problem, are there faster ways to read a matrix and store it in a form of list of lists in python.
The input is
3
3
abc
def
ghi
I need to store this as
[['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h', 'i']]
Maybe there is a way to do in something like stdin, but I have no idea what that is
Upvotes: 0
Views: 65
Reputation: 966
Try Numpy package, it is faster than the python list. The main difference is about the performance. Numpy data structures perform better in:
For further information Try this link
Upvotes: 1