Python Forum
How to assign a "Score" variable to each element in a list
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to assign a "Score" variable to each element in a list
#2
This is how I handle it: I have a dictionary of player names to their scores, like {'Bob': 23, 'Ichabod': 81, 'Buckaroo': 55}. I also have a list of the players, and an index pointing to that list for the current player. Each time through the loop you update the index, and if it's equal to the length of the list you reset it to zero (really easy to do with the % operator). For a simple repeated loop through a player list, there are better options, but they involve the itertools package, which is probably beyond the scope of your homework.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Messages In This Thread
RE: How to assign a "Score" variable to each element in a list - by ichabod801 - May-15-2019, 01:19 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to update score value? Mavoz 5 2,496 Nov-08-2022, 12:37 AM
Last Post: Mavoz
  How do you find the length of an element of a list? pav1983 13 4,923 Jun-13-2020, 12:06 AM
Last Post: pav1983
  Methods that return the highest score from the list erfanakbari1 7 7,183 Mar-26-2019, 08:32 PM
Last Post: aankrose
  New to Python - tiny coding assistance on user input function and assign to variable Mountain_Duck 1 2,528 Mar-23-2019, 06:54 PM
Last Post: Yoriz
  Extracting list element with user input valve 1 2,589 Mar-11-2019, 07:37 PM
Last Post: Yoriz
  Average score MartinEvtimov 5 6,868 Apr-02-2017, 07:35 PM
Last Post: ichabod801
  maximum and minimum element from the list and return output in dict MeeranRizvi 1 3,755 Jan-02-2017, 02:12 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020