Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
list, filter, join, lambda solution in Clear category for Sum by Type by baca90
def sum_by_types(items: list[str, int]) -> tuple[str, int] | list[str, int]:
return ["".join(filter(lambda x: type(x) == str, items)), sum(filter(lambda x: type(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. 14, 2022
Comments: