Using the same key in two dictionaries (Python)
Question: Here's what I have:

    
    
    from pprint import pprint
    
    Names = {}
    Prices = {}
    Exposure = {}
    
    def AddName():
        company_name = input("Please enter company name: ")
        return company_name
    
    def AddSymbol(company_name):
        stock_symbol = input("Please enter a stock symbol: ")
        Names[stock_symbol] = company_name
        return Names
    

^^ this updates the Names dictionary fine as {symbol:company name}

    
    
    def AddPrices(stock_symbol):
        buy = float(input("Please enter buying price of stock: "))
        sell = float(input("Please enter current price of stock: "))
        Prices[stock_symbol] = buy, sell
        return Prices
    

^^ this generates a TypeError: unhashable type: 'dict' - what I want is it to
update the Prices dictionary like {symbol: buy price, sell price, symbol2: buy
price, sell price etc..}

    
    
    def printDicts(Names, Prices):
        '''
        For debug purposes, prints out contents of dictionaries
        '''
        print( "Names is now:" )
        pprint(Names)
    
        print("Prices now:")
        pprint(Prices)
    
    
    
    def main():
        company_name = AddName()
        stock_symbol = AddSymbol(company_name)
        AddPrices(stock_symbol)
        printDicts(Names, Prices)
    
    main()
    

Being new to programming I'm not entirely sure how to fix this. Thanks for any
help!


Answer: Your `AddSymbol` returns `Names`, which is dictionary. Dictionary can't be
used as dictionary key.

Just use `return stock_symbol` in `AddSymbol`.

