I get the feeling this is probably something I should know but I can’t think of it right now. I’m trying to get a function to build a list where the name of the list is an argument given in the function;
e.g.
def make_hand(deck, handname): handname = [] for c in range(5): handname.append(deck.pop()) return handname # deck being a list containing all the cards in a deck of cards earlier
The issue is that this creates a list called handname when i want it to be called whatever the user enters as handname when creating the hand.
Anyone can help? thanks
You can keep a dictionary where the keys are the name of the hand and the values are the list.
Then you can just say dictionary[handname] to access a particular hand. Along the lines of: