Advertisement
Guest User

Untitled

a guest
Jan 29th, 2020
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. import os
  2. import json
  3. import hashlib
  4.  
  5. def problema1(text):
  6. dicti = {}
  7. for a in text:
  8. if a in dicti:
  9. dicti[a] +=1
  10. else:
  11. dicti[a] = 0
  12. return max(dicti, key = dicti.get)
  13.  
  14.  
  15. def problema2(dir_path):
  16. my_list = []
  17. files = os.listdir(dir_path)
  18. for file in files:
  19. full_path=os.path.join(dir_path, file)
  20. if os.path.isfile(full_path):
  21. my_list.append(file)
  22. return sorted(my_list)
  23.  
  24. def problema3(my_path):
  25. while True:
  26. with open(my_path) as my_json:
  27. data_json = json.load(my_json)
  28. if "next" in data_json:
  29. my_path = data_json["next"]
  30. else:
  31. return os.path.getsize(my_path)
  32.  
  33. def problema4(dir_path, to_find):
  34. my_vec = []
  35. for root, directories, files in os.walk(dir_path):
  36. for file in files:
  37. full_path = os.path.join(root, file)
  38. with open(full_path, "rb") as fd:
  39. abs_file = os.path.abspath(file)
  40. hasher = hashlib.sha1()
  41. hasher.update(fd.read())
  42. hash = hasher.hexdigest()
  43. print(hash)
  44. if hash == to_find:
  45. my_vec.append(abs_file)
  46. return sorted(my_vec)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement