Advertisement
Blatwurst

Untitled

Oct 17th, 2020
2,464
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.73 KB | None | 0 0
  1. I think this is what you wanted, or it's at least close enough that you could tweak it if it isn't quite right.  It assumes the data is well formed.  Specifically, it does not check how many numbers are on each of the matrix lines:
  2.  
  3.     def readints(f):
  4.         return [int(x) for x in f.readline().split('/')[0].split()]
  5.    
  6.     with open("data.txt") as f:
  7.         m = readints(f)[0]
  8.         n = readints(f)[0]
  9.         p = readints(f)[0]
  10.         A = []
  11.         for i in range(m):
  12.             A.append(readints(f))
  13.         B = []
  14.         for i in range(n):
  15.             B.append(readints(f))
  16.    
  17.     print(m,n,p)
  18.     print(A)
  19.     print(B)
  20.  
  21. Result:
  22.  
  23.     3 2 4
  24.     [[1, 2], [3, 4], [5, 6]]
  25.     [[7, 8, 9, 10], [11, 12, 13, 14]]
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement