Search code examples
pythondictionarycomparisonuser-input

How can I get user input to reference the name of a dictionary with the same name as the input?


I'm trying to create a program that will compare dictionaries and choose the best game choice based on the preferences set in the dictionaries. This involves the user input the list of people's names who are participating, then the program must take those names, take the dictionaries of those names and compare them.

But I can't figure out how to take the list of names given by the user input (which are str type I guess) to become the names of the dictionary variables.... this is what I have so far:

Morgan = {
    "Social Deduction" : 5,
    "Deck Building" : 2,
    "Dice games" : 3,
    "classic Card Games" : 5,
    "Simple Party Games" : 5,
    "Strategy" : 3,
    "Deduction" : 4,
    "Blacklist" : "Deception"
    }

Adam = {
    "Social Deduction" : 5,
    "Deck Building" : 5,
    "Dice games" : 5,
    "classic Card Games" : 5,
    "Simple Party Games" : 5,
    "Strategy" : 5,
    "Deduction" : 5,
    }

Guy = {
    "Social Deduction" : 1,
    "Deck Building" : 2,
    "Dice games" : 5,
    "classic Card Games" : 5,
    "Simple Party Games" : 2,
    "Strategy" : 3,
    "Deduction" : 4,
    }

def main():
    accepted = input('Who is coming today? ').split(",")
    for i in range(len(accepted)-1):
        print(i)
        if i==0:
            print(cumulativeComp = accepted[i].items() & accepted[i+1].items())
        elif i < len(accepted)-1:
            print(cumulativeComp = cumulativeComp.items() & accepted[i+1].items())
        else:
            pass

if __name__== "__main__":
    main()  

Any thoughts or suggestions?


Solution

  • Make a dictionary of dictionaries:

    game_preferences = {
       "Morgan" : {
        "Social Deduction" : 5,
        "Deck Building" : 2,
        "Dice games" : 3,
        "classic Card Games" : 5,
        "Simple Party Games" : 5,
        "Strategy" : 3,
        "Deduction" : 4,
        "Blacklist" : "Deception"
        },
       "Adam" : {
        "Social Deduction" : 5,
        "Deck Building" : 5,
        "Dice games" : 5,
        "classic Card Games" : 5,
        "Simple Party Games" : 5,
        "Strategy" : 5,
        "Deduction" : 5,
        },
       "Guy" : {
        "Social Deduction" : 1,
        "Deck Building" : 2,
        "Dice games" : 5,
        "classic Card Games" : 5,
        "Simple Party Games" : 2,
        "Strategy" : 3,
        "Deduction" : 4,
        },
       }