Advertisement
JV777

py

Dec 13th, 2020
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. import os
  2.  
  3. class Month:
  4. name = ""
  5. dict_days = {}
  6. def __init__(self, name):
  7. self.name = name
  8. class Day:
  9. name = ""
  10. files = []
  11. def __init__(self, name):
  12. self.name = name
  13. def get_files_count(self):
  14. print(len(self.files))
  15.  
  16.  
  17. files_list = os.listdir("test")
  18. number_files = len(files_list)
  19.  
  20. dict_month = {}
  21.  
  22. # переменная count создана для проверки количества создания записей
  23. count = 0
  24.  
  25. for file in files_list:
  26. month = file[5] + file[6]
  27. day = file[8] + file[9]
  28.  
  29. # проверяем, существует ли месяц и день в наших словарях
  30. while True:
  31. if(month in dict_month):
  32.  
  33. if(day in dict_month[month].dict_days):
  34.  
  35. break
  36. else:
  37. dict_month[month].dict_days[day] = Day(day)
  38.  
  39. break
  40. else:
  41.  
  42. dict_month[month] = Month(month)
  43. count += 1
  44.  
  45. dict_month[month].dict_days[day].files.append(file)
  46.  
  47. # Вывод результата
  48. for m in dict_month:
  49. print(f"Month is: {m}")
  50. for d in dict_month[m].dict_days:
  51. print(f"\tDay is: {d}")
  52. for f in dict_month[m].dict_days[d].files:
  53. print(f"\t{f}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement