Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
join + zip + sum solution in Clear category for Sum by Type by kdim
from typing import Tuple
def sum_by_types(items: list) -> Tuple[str, int]:
s, n = list(zip(*[['', 0]] + [[i, 0] if isinstance(i, str) else ['', i] for i in items]))
return ("".join(s), sum(n))
Jan. 27, 2021
Comments: