joseleeph

Untitled

Dec 1st, 2020
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. from sys import argv, exit
  2. import re
  3. if len(argv) < 2:
  4. print("mising command-line argument")
  5. exit(1)
  6.  
  7. with open(argv[1], "r") as f:
  8. count = 0
  9. contents = f.read()
  10. print(contents)
  11. print(contents[0:4])
  12. i = 0
  13. j = i + 4
  14. while contents[i:j]: # will read contents until end of file
  15. span = contents[i:j] # span will be a substring of contents from i to j
  16. while contents[i+4:j+4] == span: # while the next 4 indices have the same values of the index span
  17. count += 1
  18. i += 4
  19. j += 4
  20. i += 4
  21. j += 4
  22. print("span " + span + " repeats " + str(count) + " times" )
Advertisement
Add Comment
Please, Sign In to add comment