import pprint #import library

nhl_teams = {
    "League": "NHL",
    "Country": "North America",
    "Current Season": '2022-2023',
    "Teams": {
        1: "Boston Bruins",
        2: "Chicago Blackhawks",
        3: "Toronto Maple Leafs",
        4: "Los Angeles Kings",
        5: "Edmonton Oliers",
        
    }
}

# Printing the dictionary
pprint.pprint(nhl_teams)
{'Country': 'North America',
 'Current Season': '2022-2023',
 'League': 'NHL',
 'Teams': {1: 'Boston Bruins',
           2: 'Chicago Blackhawks',
           3: 'Toronto Maple Leafs',
           4: 'Los Angeles Kings',
           5: 'Edmonton Oliers'}}
pprint.pprint(nhl_teams.get('Teams'))
{1: 'Boston Bruins',
 2: 'Chicago Blackhawks',
 3: 'Toronto Maple Leafs',
 4: 'Los Angeles Kings',
 5: 'Edmonton Oliers'}
pprint.pprint(nhl_teams.get('League'))
'NHL'
nhl_teams["Best Players"] = (['David Pastarnak', 'Conner Mcdavid', 'Auston Mattphews', 'David Pastarnak', 'Linus Ullmark', 'Alex Ovechkin'])
# What can you change to make sure there are no duplicate players?

# Take out a duplicate
# Make it into a set

# Printing the dictionary
pprint.pprint(nhl_teams)
{'Best Players': ['David Pastarnak',
                  'Conner Mcdavid',
                  'Auston Mattphews',
                  'David Pastarnak',
                  'Linus Ullmark',
                  'Alex Ovechkin'],
 'League': 'NHL',
 'country': 'North America',
 'current season': '2022-2023',
 'teams': {1: 'Boston Bruins',
           2: 'Chicago Blackhawks',
           3: 'Toronto Maple Leafs',
           4: 'Los Angeles Kings',
           5: 'Edmonton Oliers'}}
# removing duplicate elements from the list
print("Original List: ", nhl_teams['Best Players'])
res = [*set(nhl_teams['Best Players'])]
print("List after removing duplicate elements: ", res)
Original List:  ['David Pastarnak', 'Conner Mcdavid', 'Auston Mattphews', 'David Pastarnak', 'Linus Ullmark', 'Alex Ovechkin']
List after removing duplicate elements:  ['Auston Mattphews', 'David Pastarnak', 'Linus Ullmark', 'Alex Ovechkin', 'Conner Mcdavid']
nhl_teams["Teams"].update({6:"New York Rangers"})

# How would add an additional team 
# use .update
#  filter to teams, add new number key they type team name

# Printing the dictionary
pprint.pprint(nhl_teams)
{'Country': 'North America',
 'Current Season': '2022-2023',
 'League': 'NHL',
 'Teams': {1: 'Boston Bruins',
           2: 'Chicago Blackhawks',
           3: 'Toronto Maple Leafs',
           4: 'Los Angeles Kings',
           5: 'Edmonton Oliers',
           6: 'New York Rangers'}}
for k,v in nhl_teams.items(): # iterate using a for loop for key and value
    print(str(k) + ": " + str(v))

# Write your own code to print tracks in readable format

# use pprint library
League: NHL
country: North America
current season: 2022-2023
teams: {1: 'Boston Bruins', 2: 'Chicago Blackhawks', 3: 'Toronto Maple Leafs', 4: 'Los Angeles Kings', 5: 'Edmonton Oliers', 6: 'New York Rangers'}
Best Players: ['David Pastarnak', 'Conner Mcdavid', 'Auston Mattphews', 'David Pastarnak', 'Linus Ullmark', 'Alex Ovechkin']
def search():
    search = input("What would you like to know about the NHL? \n For teams type --> Teams")
    if nhl_teams.get(search.lower()) == None:
        print("Invalid Search")
    else:
        pprint.pprint(nhl_teams.get(search.lower()))

search()

#
#
{1: 'Boston Bruins',
 2: 'Chicago Blackhawks',
 3: 'Toronto Maple Leafs',
 4: 'Los Angeles Kings',
 5: 'Edmonton Oliers',
 6: 'New York Rangers'}
# Define the options as a list
options = []

for k,v in nhl_teams.items(): # iterate using a for loop for key and value
    options.append(str(k.lower()))

# Define the menu function
def menu():
    # Display the menu options
    print('\n Select an option from the list below:')
    for option in options:
        print(option)

    # user input
    search = input("What would you like to know about ...").lower()

    # Find the selected option in the options list
    selected_option = None
    for option in options:
        if search == str(option):
            selected_option = str(option)
            break
    

    if selected_option == "Teams":
        print(f'\n Teams: {nhl_teams[options[0]]} \n')
    elif selected_option == "League":
        print(f'\n League: {nhl_teams[options[1]]} \n')
    elif selected_option == "Country":
        print(f'\n Country: {nhl_teams[options[2]]} \n')
    elif selected_option == "Teams":
        print("\n Teams(s):")
        for g in nhl_teams['Teams']:
            print(f"- {g}")
    else:
        print("\n Please try again. \n")

    # Repeat the menu
    menu()

menu()
 Select an option from the list below:
league
country
current season
teams

 Please try again. 


 Select an option from the list below:
league
country
current season
teams

 Please try again. 


 Select an option from the list below:
league
country
current season
teams

 Please try again. 


 Select an option from the list below:
league
country
current season
teams

 Please try again. 


 Select an option from the list below:
league
country
current season
teams

 Please try again. 


 Select an option from the list below:
league
country
current season
teams

 Please try again. 


 Select an option from the list below:
league
country
current season
teams

 Please try again. 


 Select an option from the list below:
league
country
current season
teams

 Please try again. 


 Select an option from the list below:
league
country
current season
teams

 Please try again. 


 Select an option from the list below:
league
country
current season
teams

 Please try again. 


 Select an option from the list below:
league
country
current season
teams

 Please try again. 


 Select an option from the list below:
league
country
current season
teams

 Please try again. 


 Select an option from the list below:
league
country
current season
teams

 Please try again. 


 Select an option from the list below:
league
country
current season
teams

 Please try again. 


 Select an option from the list below:
league
country
current season
teams

 Please try again. 


 Select an option from the list below:
league
country
current season
teams

 Please try again. 


 Select an option from the list below:
league
country
current season
teams

 Please try again. 


 Select an option from the list below:
league
country
current season
teams

 Please try again. 


 Select an option from the list below:
league
country
current season
teams
---------------------------------------------------------------------------
KeyboardInterrupt                         Traceback (most recent call last)
/vscode/ahadsblog/_notebooks/2023-03-30-HashMap Hacks.ipynb Cell 9 in <cell line: 44>()
     <a href='vscode-notebook-cell://wsl%2Bubuntu/vscode/ahadsblog/_notebooks/2023-03-30-HashMap%20Hacks.ipynb#X11sdnNjb2RlLXJlbW90ZQ%3D%3D?line=40'>41</a>     # Repeat the menu
     <a href='vscode-notebook-cell://wsl%2Bubuntu/vscode/ahadsblog/_notebooks/2023-03-30-HashMap%20Hacks.ipynb#X11sdnNjb2RlLXJlbW90ZQ%3D%3D?line=41'>42</a>     menu()
---> <a href='vscode-notebook-cell://wsl%2Bubuntu/vscode/ahadsblog/_notebooks/2023-03-30-HashMap%20Hacks.ipynb#X11sdnNjb2RlLXJlbW90ZQ%3D%3D?line=43'>44</a> menu()

/vscode/ahadsblog/_notebooks/2023-03-30-HashMap Hacks.ipynb Cell 9 in menu()
     <a href='vscode-notebook-cell://wsl%2Bubuntu/vscode/ahadsblog/_notebooks/2023-03-30-HashMap%20Hacks.ipynb#X11sdnNjb2RlLXJlbW90ZQ%3D%3D?line=38'>39</a>     print("\n Please try again. \n")
     <a href='vscode-notebook-cell://wsl%2Bubuntu/vscode/ahadsblog/_notebooks/2023-03-30-HashMap%20Hacks.ipynb#X11sdnNjb2RlLXJlbW90ZQ%3D%3D?line=40'>41</a> # Repeat the menu
---> <a href='vscode-notebook-cell://wsl%2Bubuntu/vscode/ahadsblog/_notebooks/2023-03-30-HashMap%20Hacks.ipynb#X11sdnNjb2RlLXJlbW90ZQ%3D%3D?line=41'>42</a> menu()

/vscode/ahadsblog/_notebooks/2023-03-30-HashMap Hacks.ipynb Cell 9 in menu()
     <a href='vscode-notebook-cell://wsl%2Bubuntu/vscode/ahadsblog/_notebooks/2023-03-30-HashMap%20Hacks.ipynb#X11sdnNjb2RlLXJlbW90ZQ%3D%3D?line=38'>39</a>     print("\n Please try again. \n")
     <a href='vscode-notebook-cell://wsl%2Bubuntu/vscode/ahadsblog/_notebooks/2023-03-30-HashMap%20Hacks.ipynb#X11sdnNjb2RlLXJlbW90ZQ%3D%3D?line=40'>41</a> # Repeat the menu
---> <a href='vscode-notebook-cell://wsl%2Bubuntu/vscode/ahadsblog/_notebooks/2023-03-30-HashMap%20Hacks.ipynb#X11sdnNjb2RlLXJlbW90ZQ%3D%3D?line=41'>42</a> menu()

    [... skipping similar frames: menu at line 42 (15 times)]

/vscode/ahadsblog/_notebooks/2023-03-30-HashMap Hacks.ipynb Cell 9 in menu()
     <a href='vscode-notebook-cell://wsl%2Bubuntu/vscode/ahadsblog/_notebooks/2023-03-30-HashMap%20Hacks.ipynb#X11sdnNjb2RlLXJlbW90ZQ%3D%3D?line=38'>39</a>     print("\n Please try again. \n")
     <a href='vscode-notebook-cell://wsl%2Bubuntu/vscode/ahadsblog/_notebooks/2023-03-30-HashMap%20Hacks.ipynb#X11sdnNjb2RlLXJlbW90ZQ%3D%3D?line=40'>41</a> # Repeat the menu
---> <a href='vscode-notebook-cell://wsl%2Bubuntu/vscode/ahadsblog/_notebooks/2023-03-30-HashMap%20Hacks.ipynb#X11sdnNjb2RlLXJlbW90ZQ%3D%3D?line=41'>42</a> menu()

/vscode/ahadsblog/_notebooks/2023-03-30-HashMap Hacks.ipynb Cell 9 in menu()
     <a href='vscode-notebook-cell://wsl%2Bubuntu/vscode/ahadsblog/_notebooks/2023-03-30-HashMap%20Hacks.ipynb#X11sdnNjb2RlLXJlbW90ZQ%3D%3D?line=14'>15</a>     print(option)
     <a href='vscode-notebook-cell://wsl%2Bubuntu/vscode/ahadsblog/_notebooks/2023-03-30-HashMap%20Hacks.ipynb#X11sdnNjb2RlLXJlbW90ZQ%3D%3D?line=16'>17</a> # user input
---> <a href='vscode-notebook-cell://wsl%2Bubuntu/vscode/ahadsblog/_notebooks/2023-03-30-HashMap%20Hacks.ipynb#X11sdnNjb2RlLXJlbW90ZQ%3D%3D?line=17'>18</a> search = input("What would you like to know about ...").lower()
     <a href='vscode-notebook-cell://wsl%2Bubuntu/vscode/ahadsblog/_notebooks/2023-03-30-HashMap%20Hacks.ipynb#X11sdnNjb2RlLXJlbW90ZQ%3D%3D?line=19'>20</a> # Find the selected option in the options list
     <a href='vscode-notebook-cell://wsl%2Bubuntu/vscode/ahadsblog/_notebooks/2023-03-30-HashMap%20Hacks.ipynb#X11sdnNjb2RlLXJlbW90ZQ%3D%3D?line=20'>21</a> selected_option = None

File ~/anaconda3/lib/python3.9/site-packages/ipykernel/kernelbase.py:1075, in Kernel.raw_input(self, prompt)
   1071 if not self._allow_stdin:
   1072     raise StdinNotImplementedError(
   1073         "raw_input was called, but this frontend does not support input requests."
   1074     )
-> 1075 return self._input_request(
   1076     str(prompt),
   1077     self._parent_ident["shell"],
   1078     self.get_parent("shell"),
   1079     password=False,
   1080 )

File ~/anaconda3/lib/python3.9/site-packages/ipykernel/kernelbase.py:1120, in Kernel._input_request(self, prompt, ident, parent, password)
   1117             break
   1118 except KeyboardInterrupt:
   1119     # re-raise KeyboardInterrupt, to truncate traceback
-> 1120     raise KeyboardInterrupt("Interrupted by user") from None
   1121 except Exception:
   1122     self.log.warning("Invalid Message:", exc_info=True)

KeyboardInterrupt: Interrupted by user

inforgraphic