2 je30824 je30824 于 2016.04.13 20:54 提问

请教map list容器问题 5C

Write a Python function called tally that consumes a list of strings representing all the
participant’s town visits (called log) and produces a dictionary with the participants as the keys
and the total points earned as the corresponding values. Notes:
• Each element in log is a string with three comma separated values: the first value is the
participant id, the second is the town, and the third is the points earned in that town.
• If the participant visited a town more than once, then tally must assign None to that
participant’s total points to show they are disqualified.
• The list tally may be empty, but all strings in tally will be in the correct format.
• Recall dictionaries do not have an associated order: two dictionaries are equal if they
have the same set of keys, and each key has the same associated value. This means your
produced dictionary may have keys in any order when printed.
Example 1:
tally([ "jsmith,Elora,2",
"jsmith,St. Jacobs,4",
"klee,St. Jacobs,5",
=> { "jsmith" : 7, "klee" : 13, "kafka" : 3, "proth" : 4 }
Example 2:
tally([ "ricky,Linwood,4",
=> { "mog" : 2, "ricky" : None, "janed" : 5 }


devmiao   Ds   Rxr 2016.04.13 21:49
Csdn user default icon