0

I want to be able to enter a list of names and then for each name on that list I want to create a list of predictions on who each person thinks will win a match.

For example, I would have names = [bob, bill, fred]

Then for each name in that list I'd like to have the user enter who they think will win. So in this example I would end up with

bobs_predictions = []
bills_predictions = []
freds_predictions = []

Hopefully you understand what I mean. Basically I'd like to create a list of lists where python names the list based on a list of names...

erip
  • 16,374
  • 11
  • 66
  • 121
Luke Bray
  • 245
  • 2
  • 12

1 Answers1

3

You want to use a mapping:

predictions = {
    "bob": [...],
    "bill": [...],
    "fred": [...]
}

To instantiate (with empty predictions) from a list of names:

predictions = {name: [] for name in names}

To get bob's predictions:

bobs_predictions = predictions['bob']

To add a prediction to bob:

bobs_predictions.append(prediction)
Reut Sharabani
  • 30,449
  • 6
  • 70
  • 88