Advertisement
Guest User

Untitled

a guest
Aug 15th, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. import sys
  2.  
  3. if __name__ == "__main__":
  4. path = ""
  5. if len(sys.argv) < 2:
  6. print("Error!!! Usage: sh Q1.sh <filepath>")
  7. sys.exit(1)
  8. else:
  9. path = sys.argv[1]
  10.  
  11. infile = open(path,'r')
  12. otfile = open('Q1.txt','w')
  13. content = infile.readlines()
  14. conlist = content[0].split()
  15. anslist = []
  16. anscnt = []
  17. for c in conlist:
  18. if c in anslist:
  19. anscnt[anslist.index(c)] += 1
  20. else:
  21. anslist.append(c)
  22. anscnt.append(1)
  23.  
  24. sys.stdout = otfile
  25. for i in range(len(anslist)):
  26. print(anslist[i],i,anscnt[i])
  27. infile.close()
  28. otfile.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement