davegimo

Untitled

Dec 22nd, 2023
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. def txt(file,n_righe):
  2. f = open(file)
  3. lines = f.readlines()
  4.  
  5. l = []
  6. for line in lines:
  7. for c in line:
  8. l.append(ord(c))
  9.  
  10. mat = []
  11. n_columns = len(l) // n_righe + len(l) % n_righe
  12. print(len(l))
  13. print(l)
  14.  
  15. for i in range(n_righe):
  16. riga = []
  17. for j in range(n_columns):
  18. print(f"{n_columns}*{i} + {j} = {n_columns*i + j}")
  19. if n_columns*i + j >= len(l):
  20.  
  21. riga.append(0)
  22. else:
  23. riga.append(l[j*(i+1)])
  24.  
  25. mat.append(riga)
  26.  
  27. print(mat)
  28.  
  29.  
  30. txt("text/test1.txt",2)
  31.  
Advertisement
Add Comment
Please, Sign In to add comment