Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- class Month:
- name = ""
- dict_days = {}
- def __init__(self, name):
- self.name = name
- class Day:
- name = ""
- files = []
- def __init__(self, name):
- self.name = name
- def get_files_count(self):
- print(len(self.files))
- files_list = os.listdir("test")
- number_files = len(files_list)
- dict_month = {}
- # переменная count создана для проверки количества создания записей
- count = 0
- for file in files_list:
- month = file[5] + file[6]
- day = file[8] + file[9]
- # проверяем, существует ли месяц и день в наших словарях
- while True:
- if(month in dict_month):
- if(day in dict_month[month].dict_days):
- break
- else:
- dict_month[month].dict_days[day] = Day(day)
- break
- else:
- dict_month[month] = Month(month)
- count += 1
- dict_month[month].dict_days[day].files.append(file)
- # Вывод результата
- for m in dict_month:
- print(f"Month is: {m}")
- for d in dict_month[m].dict_days:
- print(f"\tDay is: {d}")
- for f in dict_month[m].dict_days[d].files:
- print(f"\t{f}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement