Answer the question
In order to leave comments, you need to log in
How can you count the amount of something that has the same name?
For example, there is a list \ tuple of strings:
("2014-01-01 01:12:13 181",
"2014-01-02 20:11:10 600",
"2014-01-03 01:12:13 6009",
"2014-01-03 12:13:55 200")
def total_cost(calls):
cost = dict()
for i in calls:
i = i.split()
cost[i[0]] = cost.get(i[0], 0) + int(i[2])
return cost
print(total_cost(("2014-01-01 01:12:13 181",
"2014-01-02 20:11:10 600",
"2014-01-03 01:12:13 6009",
"2014-01-03 12:13:55 200")))
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question