Advertisement
joseleeph

Untitled

Dec 14th, 2020
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. from sys import argv, exit
  2. import csv
  3. import re
  4. if len(argv) < 3:
  5. print("missing command line argument")
  6.  
  7. with open(argv[1],"r") as csvfile, open(argv[2],"r") as file: # arguments switched as suggested
  8. count = 0
  9. contents = file.read()
  10. csvcontents = csv.reader(csvfile)
  11.  
  12.  
  13. header = next(csvcontents)
  14.  
  15. for item in header[1:]:# is there no reason to do this?
  16. #for item in header:
  17. beg = 0 # beginning index
  18. end = len(item) # item length
  19. seqrun = 0
  20. longest = 0
  21. #index = 0
  22. while beg + end <= len(contents):
  23. seqrun = 0
  24. while contents[beg: beg + end] == item:
  25. seqrun += 1
  26. beg += end
  27. if seqrun > longest:
  28. longest = seqrun
  29. beg += 1
  30. print(item + " repeats " + str(longest) + "times")
  31.  
  32. # everything above here works... adding the code below causes the program to stop after the first string of longest repeats
  33.  
  34. for value in header:# all these embedded loops are a bit bothersome
  35. index = 0
  36. while value != item: # how else might i keep track of item?
  37. index += 1 # figure out which index matches the item, such that you can compare the value found in large.csv to row[index]
  38. for row in csvcontents:
  39. if row[index] == item:
  40. print("possible match is named: ")
  41. print(row[0])
  42. #for value in csvcontents: # look at all the values in csv contents
  43. #if csvcontents[index] == item:
  44. #print("possible match is" + str(csvcontents[0]))
  45. #return csvcontents[0]
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement