Advertisement
Guest User

Day4

a guest
Dec 5th, 2016
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. #!/usr/local/bin/python2.7
  2. import collections
  3. import sys
  4. import re
  5. from os import path
  6.  
  7. listInput = "list.txt"
  8.  
  9. def extractLetters():
  10. global listInput
  11.  
  12. sumOfAll = 0
  13.  
  14. if(path.exists(listInput) and path.getsize(listInput) > 0) :
  15. with open(listInput, "r") as filestream:
  16. for line in filestream:
  17.  
  18. final = ""
  19. sectorID = re.search("([0-9][0-9][0-9])", line).group(0)
  20.  
  21. for c in collections.Counter(line[:-11].translate(None, "-").translate(None, " ").translate(None, "\n")).most_common(8):
  22. final += c[0]
  23.  
  24. mostUsed = re.search("\[(.*)\]", line).group(0).translate(None, "[").translate(None, "]")
  25.  
  26. foundChar = 0
  27. for i in mostUsed:
  28. for j in final:
  29. if i == j:
  30. foundChar += 1
  31.  
  32. if foundChar >= 5:
  33. sumOfAll += int(sectorID)
  34.  
  35. print "Final: " + "".join(sorted(final)) + " Most Used: " + "".join(sorted(mostUsed)) + " SectorID: " + sectorID
  36.  
  37. print "Total sum: " + str(sumOfAll)
  38.  
  39.  
  40. if __name__ == "__main__":
  41. extractLetters()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement