Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i had stored result in dictionary as

playerStats={'Murray':[2,2,16,143,13,142],'Djokovic':[3,1,13,142,‌​16,143],'Muguruza':[‌​0,0,1,12,2,15],'Will‌​iams':[0,1,2,15,1,12‌​]}

Now i want to print output in decreasing order of ranking, where the ranking is according to the criteria 1-6 in that order (compare item 1, if equal compare item 2, if equal compare item 3 etc, noting that for items 5 and 6 the comparison is reversed).

print out the following.....

Djokovic 3 1 13 142 16 143

Murray 2 2 16 143 13 142

Williams 0 1 2 15 1 12

Muguruza 0 0 1 12 2 15

where criteria 1-6 are...
1. Number of best-of-5 set matches won
2. Number of best-of-3 set matches won
3. Number of sets won
4. Number of games won
5. Number of sets lost
6. Number of games lost

What I have tried:

playerNames=['Djokovic','Williams','Muguruza','Murray']
n=0
if playerStats[playerNames[n]][0]>playerStats[playerNames[n+1]][0] and playerStats[playerNames[n]][0]>playerStats[playerNames[n+2]][0] and playerStats[playerNames[n]][0]>playerStats[playerNames[n+3]][0]:
print(playerNames[n],playerStats[playerNames[n]][0],playerStats[playerNames[n]][1],playerStats[playerNames[n]][2],playerStats[playerNames[n]][3],playerStats[playerNames[n]][4],playerStats[playerNames[n]][5])
if playerStats[playerNames[n+1]][0]>playerStats[playerNames[n+2]][0] and playerStats[playerNames[n+1]][0]>playerStats[playerNames[n+3]][0]:
print(playerNames[n+1],playerStats[playerNames[n+1]][0],playerStats[playerNames[n+1]][1],playerStats[playerNames[n+1]][2],playerStats[playerNames[n+1]][3],playerStats[playerNames[n+1]][4],playerStats[playerNames[n+1]][5])


if playerStats[playerNames[n+1]][0]>playerStats[playerNames[n+2]][0] and playerStats[playerNames[n+1]][0]>playerStats[playerNames[n]][0] and playerStats[playerNames[n+1]][0]>playerStats[playerNames[n+3]][0]:
print(playerNames[n+1],playerStats[playerNames[n]][0],playerStats[playerNames[n]][1],playerStats[playerNames[n]][2],playerStats[playerNames[n]][3],playerStats[playerNames[n]][4],playerStats[playerNames[n]][5])
Posted
Updated 27-Aug-16 4:02am

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900