Answer the question
In order to leave comments, you need to log in
How to get the value by key from the first dictionary and match it with the value by key from the second one?
We have a dictionary with subdictionaries, quite large:
{
"Список": {
"0": "*Аманжуров Тимур* —",
"1": "*Блинов Денис* —",
"2": "*Григорьева Мария* —",
"3": "*Дедов Павел* —",
"4": "*Дубков Александр* —",
"5": "*Зелинский Даниил* —",
"6": "*Зотов Денис* —",
"7": "*Козлов Арсентий* —",
"8": "*Колягин Артем* —",
"9": "*Крутов Данил* —",
"10": "*Кряженкова Алина* —",
"11": "*Меньшов Геннадий* —",
"12": "*Мишина Алина* —",
"13": "*Наговский Даниил* —",
"14": "*Нагорных Максим* —",
"15": "*Овсянников Вячеслав* —",
"16": "*Петренко Вадим* —",
"17": "*Прощаев Максим* —",
"18": "*Пугин Андрей* —",
"19": "*Сергеев Илья* —",
"20": "*Совгирь Виктор* —",
"21": "*Талызин Валерий* —",
"22": "*Фокин Александр* —",
"23": "*Хромов Андрей* —",
"24": "*Чеснокова Анна* —",
"25": "*Штернфельд Олег* —"
},
"Проценты": {
"0": 21,
"1": 12,
"2": 21,
"3": 22,
"4": 15,
"5": 23,
"6": 21,
"7": 19,
"8": 21,
"9": 25,
"10": 35.4,
"11": 15,
"12": 26.4,
"13": 23,
"14": 22,
"15": 26.4,
"16": 0,
"17": 17,
"18": 22,
"19": 0,
"20": 44.1,
"21": 10,
"22": 10,
"23": 26.8,
"24": 30,
"25": 25
}
}
for x, y in zip(rating, percents):
rating_cources = rating.get(str(key))
percent_cources = percents.get(str(key))
key += 1
layout += f'{rating_cources} {percent_cources}%\n'
Answer the question
In order to leave comments, you need to log in
# проходим по словарю с фамилиями
for key, value in rating.items():
rating_cources = value
# и по ключу из первого словаря берем значения из второго
percent_cources = percents.get(key)
layout += f'{rating_cources} {percent_cources}%\n'
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question