Successful Payment Totals
Imagine a CSV export where each row contains a user, a status, and an amount. Given rows in the format user,status,amount, sum the amounts for each user, counting only rows with status success. Users with no successful rows should have a total of 0. Return pairs [user, total] sorted by user name.
Примеры
Ввод
["alice,success,100", "bob,success,50", "alice,failed,200"]Вывод
[["alice", 100], ["bob", 50]]Ввод
["alice,success,100", "alice,success,40"]Вывод
[["alice", 140]]Ввод
["x,failed,500"]Вывод
[["x", 0]]Нужно реализовать
def transaction_totals(rows):
Теги
stringshashmaparray
Log ind for at se indsendelseshistorik
Log indLog ind for at bruge AI-mentor
Log indVisible tests
1
Input
["alice,success,100","bob,success,50","alice,failed,200"]Expected
[["alice",100],["bob",50]]2
Input
["alice,success,100","alice,success,40"]Expected
[["alice",140]]3
Input
["x,failed,500"]Expected
[["x",0]]4
Input
[]Expected
[]5
Input
["b,success,10","a,success,20","b,failed,5"]Expected
[["a",20],["b",10]]6
Input
["b,success,10"]Expected
[["b",10]]Focus radio
Paused · SomaFM · Fluid