У меня есть таблица, откуда я беру всю информацию, чтобы заполнить все эти словари, однако, в конце концов, все ключи имеют одинаковые значения. Почему это происходит? Как это можно исправить?
book = xlrd.open_workbook("1k.xlsx")
sheet = book.sheet_by_index(0)
num_cols = sheet.ncols
num_rows = sheet.nrows
groups_list = []
for col_index in range(num_cols):
group_cell = str(sheet.cell(1, col_index).value)
if "-18" in group_cell:
groups_list.append(group_cell)
groups_list = dict.fromkeys(groups_list, [
dict.fromkeys(["ПОНЕДЕЛЬНИК", "ВТОРНИК", "СРЕДА", "ЧЕТВЕРГ", "ПЯТНИЦА", "СУББОТА"], dict.fromkeys(["1 пара", "2 пара", "3 пара", "4 пара", "5 пара", "6 пара"], dict.fromkeys(["Предмет", "Преподаватель", "Аудитория", "Вид занятия"]))),
dict.fromkeys(["ПОНЕДЕЛЬНИК", "ВТОРНИК", "СРЕДА", "ЧЕТВЕРГ", "ПЯТНИЦА", "СУББОТА"], dict.fromkeys(["1 пара", "2 пара", "3 пара", "4 пара", "5 пара", "6 пара"], dict.fromkeys(["Предмет", "Преподаватель", "Аудитория", "Вид занятия"])))])
for col_index in range(num_cols):
for group in groups_list.keys():
if group == str(sheet.cell(1, col_index).value):
row_index = 3
for day, couples in groups_list[group][0].items():
for couple in couples.keys():
groups_list[group][0][day][couple]['Предмет'] = str(sheet.cell(row_index, col_index).value)
groups_list[group][0][day][couple]['Вид занятия'] = str(sheet.cell(row_index, col_index+1).value)
groups_list[group][0][day][couple]['Преподаватель'] = str(sheet.cell(row_index, col_index+2).value)
groups_list[group][0][day][couple]['Аудитория'] = str(sheet.cell(row_index, col_index+3).value)
row_index += 2
В последнем цикле я выводил информацию, которая была назначена там клавишам, однако, если она выводится в других циклах или вне циклов, то вывод будет неправильным