Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Sum by Type by book1978
def sum_by_types(items: list[str, int]) -> tuple[str, int] | list[str, int]:
return [''.join(filter(lambda x: isinstance(x, str), items)), sum(filter(lambda x: isinstance(x, int), items))]
print("Example:")
print(list(sum_by_types([])))
assert list(sum_by_types([])) == ["", 0]
assert list(sum_by_types([1, 2, 3])) == ["", 6]
assert list(sum_by_types(["1", 2, 3])) == ["1", 5]
assert list(sum_by_types(["1", "2", 3])) == ["12", 3]
assert list(sum_by_types(["1", "2", "3"])) == ["123", 0]
assert list(sum_by_types(["size", 12, "in", 45, 0])) == ["sizein", 57]
print("The mission is done! Click 'Check Solution' to earn rewards!")
Dec. 13, 2022