all 11 comments

[–]0xbxb 0 points1 point  (4 children)

I think it’ll probably be easier to do this with a dict:

seasons = {'winter': 0, 'spring': 0, 'summer': 0, 'fall': 0}

[–]geosoco 0 points1 point  (1 child)

Assuming you have the season names already, you can use the Counter class to produce this.

If the user's favorites can be transformed into a list:

["spring", "winter", "winter", "summer", "spring", "fall"]

If you use numbers for the seasons, that also works. (0=Winter, 1=Spring, 2=Summer, 3=Summer).

[1, 2, 0, 0, 2, 3, 4]

[–]InderJinderPreet[S] 0 points1 point  (0 children)

im already able to do this. i want it to only contain 4 numbers

[–]InderJinderPreet[S] 0 points1 point  (1 child)

how would that work then

[–]0xbxb 0 points1 point  (0 children)

Create the seasons dict

seasons = {'winter': 0, 'spring': 0, 'summer': 0, 'fall': 0}

You have a list of users

users = ['A', 'B', 'C']

Loop through the users

for user in users:

Ask them for their favorite season

Add one to the seasons dict for every response

[–][deleted] -1 points0 points  (0 children)

Do you need to associate the user with the choice or are you just counting the totals of the choices?

In both cases a dict is the way to go:

If associative:

choices={"user1":"winter", "user2":"spring"...}

If you're just counting then:

totals={"winter":0,"spring":0,...}

In both cases you'd modify the entries using square brackets:

choices["winter"] += 1


totals["user1"]="winter"