Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
List calculation
#3
You can start with this:
Team1Points = Maths[Ranking_Maths.index(Team[0])]
Team2Points = Maths[Ranking_Maths.index(Team[1])]
Team3Points = Maths[Ranking_Maths.index(Team[2])]
Team4Points = Maths[Ranking_Maths.index(Team[3])]
Then you realize that TeamPoints should be a dictionary instead of individual variables.
TeamPoints = {'A':0, 'B':0, 'C':0, 'D':0}
Scores = [
    [15, 12, 10, 8],
    [14, 13, 12, 11],
    [13, 12, 11, 10],
    [8, 9, 7, 6],
    [8, 7, 6, 5]]
Rankings = [
    ['A', 'B', 'C', 'D'],
    ['B', 'C', 'D', 'A'],
    ['C', 'D', 'A', 'B'],
    ['D', 'A', 'B', 'C'],
    ['B', 'C', 'D', 'A']]
 
for team in TeamPoints:
    for score, rank in zip(Scores, Rankings):
        TeamPoints[team] += score[rank.index(team)]
 
for team, points in TeamPoints.items():
    print(team, points)
Reply


Messages In This Thread
List calculation - by rturus - Mar-30-2021, 12:04 PM
RE: List calculation - by Larz60+ - Mar-30-2021, 08:29 PM
RE: List calculation - by deanhystad - Mar-31-2021, 05:33 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  calculation with list in list gianniskampanakis 13 4,692 Aug-09-2019, 12:01 PM
Last Post: gianniskampanakis

Forum Jump:

User Panel Messages

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