Roxaq

DESAFIO IP - UP1

Oct 20th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.72 KB | None | 0 0
  1. import os
  2.  
  3. dir_list = os.listdir(path=os.getcwd())
  4. new_list = []
  5. res_list = []
  6. dic = {}
  7. ocorre = 0
  8. nome = input("Qual nome deseja procurar: ")
  9. for i in dir_list:
  10.     if(".txt" in i):
  11.         new_list.append(i)
  12.     if("resultado.txt" in i):
  13.         new_list.remove("resultado.txt")
  14. for i in new_list:
  15.     ocorre = 0
  16.     pr = open(i, "r")
  17.     arquivos = pr.readlines()
  18.     for j in arquivos:
  19.         if (nome in j):
  20.             ocorre += 1
  21.             dic[i] = ocorre
  22.         else:
  23.             dic[i] = ocorre
  24. pr.close()
  25. for g in dic.keys():
  26.     res = str(g) + ": " + str(dic[g]) + "\n"
  27.     res_list.append(res)
  28.     arqf = open("resultado.txt", "w")  
  29.     arqf.writelines(sorted(res_list))
  30.     arqf.close()
Advertisement
Add Comment
Please, Sign In to add comment