Demonstrates nested sequences : Nested List « List « Python






Demonstrates nested sequences

Demonstrates nested sequences
scores = []

# add score
name = raw_input("What is the player's name?: ")
score = int(raw_input("What score did the player get?: "))
entry = (score, name)
scores.append(entry)
scores.sort()
scores.reverse()        # want the highest number first
scores = scores[:5]     # keep only top 5 scores

# display
print "High Scores\n"
print "NAME\tSCORE" 
for entry in scores:
    score, name = entry    
    print name, "\t", score


           
       








Related examples in the same category

1.Nest lists (create lists containing other lists)Nest lists (create lists containing other lists)
2.A list of lists: nested listA list of lists: nested list