Skip to content
Advertisement

Python – How do I take items from a list and assign them to values in a dictionary?

I’m trying to make a function that creates a dictionary of “player stats”, based off of inputs from the user. However I’m running into several issues with my code and I know there are better ways of programming this but I can’t figure out what they are.

JavaScript

I think much of the issue is from the way I’m trying to place the stats into my dictionary. However what I have mostly works for what I need, but the first issue is if for example I set my strength to 12 points, the 15 will pop from the list and I’m not sure how to make the 12 pop instead. Also, for some reason “print(f”You have selected {statSelect1} as your base Strength!”)” is not printing.

Advertisement

Answer

Use remove to remove an element by value.

Also use a loop to iterate over the stats:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement