Reputation: 29
I used a dictionary to show all the skins that a champ has. Is it possible to use this same list to show all the champs that have a certain skin in common? For Example, if katarina and ekko both had 'Firelight' as skins, I could input 'firelight' and the return would be 'ekko, katarina'.
ekko_skins = ['Firelight', 'Pulsefire', 'True Damage', 'Sandstorm', 'Academy', 'Project: Ekko', 'Start Gardian']
kat_skins = ['Mercenary', 'Battle Academia', 'Blood Moon', 'Battle Queen', 'High Noon', 'Red Card', 'Bilgewater', 'Kitty Cat', 'Slay Belle', 'Death Sworn']
champ_skin_dict = {'ekko': [ekko_skins], 'katarina': [kat_skins]}
while True:
user_champ = input('Champion: ').lower()
print(champ_skin_dict[user_champ])
continue
Upvotes: 2
Views: 68
Reputation: 966
This should work:
ekko_skins = ['Firelight', 'Pulsefire', 'True Damage', 'Sandstorm', 'Academy', 'Project: Ekko', 'Start Gardian', 'Some skin in common']
kat_skins = ['Mercenary', 'Battle Academia', 'Blood Moon', 'Battle Queen', 'High Noon', 'Red Card', 'Bilgewater', 'Kitty Cat', 'Slay Belle', 'Death Sworn', 'Some skin in common']
champ_skin_dict = {'ekko': ekko_skins, 'katarina': kat_skins}
while True:
user_skin = input('Skin: ').lower()
print(', '.join([j for j in champ_skin_dict.keys() if user_skin in [i.lower() for i in champ_skin_dict[j]]]))
should_continue = input('Would you like to input another skin? y/n ').lower()
if should_continue == 'n':
break
Output:
Skin: Pulsefire
ekko
Would you like to input another skin? y/n y
Skin: Some skin in common
ekko, katarina
Would you like to input another skin? y/n n
Every time the user inputs a skin, this just iterates through the dictionary and only returns the keys with the user inputed skin in them. The .join
is used to put a comma in between every champion with the skin.
Also for some reason when you created the dictionary like so:
{'ekko': [ekko_skins], 'katarina': [kat_skins]}
You put the list
of skins in square brackets which would make the 1 dimensional list look like this:
[['some list item', 'another list item']]
To avoid this just make the dictionary like I did, like this:
{'ekko': ekko_skins, 'katarina': kat_skins}
Multi dimensional lists (or arrays/matrixes/tensors as they are more commonly called. They do have differences though, see this article) are used to represent multidimensional data like that stored in a dict
.
Upvotes: 1