Ниже вы найдете ввод, вывод и желаемый результат:

Вход:

Seasons = ['2013-14', '2014-15', '2015-16']
SeasonType = ['Regular Season', 'Playoffs']

myDict = {'LeagueID': '00', 'Season': Seasons, 'SeasonType': SeasonType}

for Sea in Seasons:
  for typ in SeasonType:
    print(myDict)

Выход :

{'LeagueID': '00', 'Season': ['2013-14', '2014-15', '2015-16'], 'SeasonType': ['Regular Season', 'Playoffs']}
{'LeagueID': '00', 'Season': ['2013-14', '2014-15', '2015-16'], 'SeasonType': ['Regular Season', 'Playoffs']}
{'LeagueID': '00', 'Season': ['2013-14', '2014-15', '2015-16'], 'SeasonType': ['Regular Season', 'Playoffs']}
{'LeagueID': '00', 'Season': ['2013-14', '2014-15', '2015-16'], 'SeasonType': ['Regular Season', 'Playoffs']}
{'LeagueID': '00', 'Season': ['2013-14', '2014-15', '2015-16'], 'SeasonType': ['Regular Season', 'Playoffs']}
{'LeagueID': '00', 'Season': ['2013-14', '2014-15', '2015-16'], 'SeasonType': ['Regular Season', 'Playoffs']}

Требуемый результат:

{'LeagueID': '00', 'Season': '2013-14', 'SeasonType': 'Regular Season'}
{'LeagueID': '00', 'Season': '2014-15', 'SeasonType': 'Regular Season'}
{'LeagueID': '00', 'Season': '2015-16', 'SeasonType': 'Regular Season'}
{'LeagueID': '00', 'Season': '2013-14', 'SeasonType': 'Playoffs'}
{'LeagueID': '00', 'Season': '2014-15', 'SeasonType': 'Playoffs'}
{'LeagueID': '00', 'Season': '2015-16', 'SeasonType': 'Playoffs'}

Кто-нибудь знает, возможно ли это?

-2
stathamos 20 Янв 2021 в 11:13

2 ответа

Лучший ответ
for typ in SeasonType:
  myDict['SeasonType'] = typ
  for Sea in Seasons:
    myDict['Season'] = Sea
    print(myDict)
0
Harney 20 Янв 2021 в 10:41

Вам просто нужно выбрать, что показывать, сделать это можно так:

for Sea in Seasons:
  for typ in SeasonType:
     print({'LeagueID': '00', 'Season': Sea, 'SeasonType': typ}
0
Gamopo 20 Янв 2021 в 08:18