Mam słownik z kluczami bez wartości:
teams = {'Chelsea': '', 'Manchester City': '', 'Aston Villa': '',
'Wolves': '', 'Crystal Palace': '', 'Tottenham': '',
'Leeds': '', 'West Ham': '', 'Southampton': '',
'Nottingham': '', 'Arsenal': '', 'Newcastle': '',
'Everton': '', 'Brighton': '', 'Leicester': '',
'Fulham': '', 'Manchester Utd': '', 'Bournemouth': '',
'Brentford': '', 'Liverpool': ''}
i dwie listy:
pierwsza lista zsp zawiera druzyny ,a druga lista wyniki:
Chciałym przypisać do istniejącego słownika wartości z listy wyniki.
Klucz ze słownika pobiera wartośći na podstawie występowania klucza na liście zsp. Listy zsp i wyniki zawierają takie samie ilości elementów bo są to gole strzelone dla drużyn.
zsp = ['Chelsea', 'Manchester City', 'Aston Villa', 'Wolves',
'Crystal Palace', 'Tottenham', 'Leeds', 'West Ham', 'Southampton',
'Nottingham', 'Arsenal', 'Newcastle', 'Everton', 'Brighton',
'Leicester', 'Fulham', 'Manchester Utd', 'Bournemouth', 'Brentford',
'Liverpool', 'Nottingham', 'Chelsea', 'Tottenham', 'Aston Villa',
'Bournemouth', 'Crystal Palace', 'Brighton', 'Arsenal', 'Fulham',
'Southampton', 'Manchester City', 'Everton', 'Newcastle', 'Leeds',
'Wolves', 'Manchester Utd', 'Liverpool', 'Leicester', 'West Ham',
'Brentford', 'Leeds', 'Manchester City', 'Chelsea', 'Bournemouth',
'Manchester Utd', 'Nottingham', 'Arsenal', 'West Ham', 'Aston Villa',
'Liverpool', 'Brentford', 'Tottenham', 'Crystal Palace', 'Fulham',
'Everton', 'Wolves', 'Leicester', 'Newcastle', 'Southampton',
'Brighton', 'Brighton', 'Aston Villa', 'Fulham', 'Manchester Utd',
'Bournemouth', 'Everton', 'Liverpool', 'Southampton',
'Manchester City', 'Brentford', 'Newcastle', 'Chelsea', 'Nottingham',
'Crystal Palace', 'Tottenham', 'Leeds', 'West Ham', 'Leicester',
'Wolves', 'Arsenal', 'Aston Villa', 'Manchester Utd', 'Chelsea',
'Arsenal', 'Southampton', 'Newcastle', 'Tottenham', 'Liverpool',
'West Ham', 'Crystal Palace', 'Everton', 'Leicester', 'Leeds',
'Bournemouth', 'Manchester City', 'Fulham', 'Nottingham', 'Brentford',
'Chelsea','Everton']
wyniki = [0, 1, 1, 1, 0, 4, 2, 2, 0, 1, 0, 0, 1, 4, 0, 1, 3, 0, 3, 1, 1, 1,
0, 2, 0, 2, 2, 4, 2, 1, 1, 1, 0, 0, 0, 1, 2, 1, 0, 2, 1, 3, 2, 0,
3, 0, 3, 1, 1, 3, 2, 2, 0, 3, 1, 2, 0, 3, 1, 3, 1, 2, 1, 2, 3, 0,
3, 1, 1, 2, 1, 0, 1, 0, 4, 3, 0, 2, 0, 2, 3, 1, 0, 1, 1, 4, 1, 2,
1, 2, 0, 2, 4, 3, 2, 1, 2, 2, 2, 3]
Przykładowo chciałbym ,aby tak to wyglądało:
teams = {'Chelsea': 0,1,1...itp, 'Manchester City': 1,1,2...itp}
Z listami nie miałbym problemu ,ale od wczoraj przerabiam słowniki i ciężko jest przypisywać wartości do klucz.
Na listach wykorzystałbym index ze słownika ,sprawdziłym występowanie na liście zsp i poprał metodą append wartości z listy wyniki ,a na słownikach nie jest to takie proste.
Prosiłbym o jakiś przykład.
Pozdrawiam