0

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

1
  • @vnikonov_63 if you would vote up I would appreciate it. Thank you! Commented Jun 18, 2020 at 7:09

1 Answer 1

1

Try Numpy package, it is faster than the python list. The main difference is about the performance. Numpy data structures perform better in:

  • Size: Numpy data structures take less space than the list.
  • Performance: They have a need for speed and are faster than lists.
  • Functionality: Numpy and Scipy have optimized functions such as linear algebra operations.

For further information Try this link

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

Comments

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.