Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
sum-by-type.First solution in Clear category for Sum by Type by poa
def sum_by_types(items: list[str | int]) -> tuple[str | int] | list[str | int]:
n = []
s = []
for w in items:
if type(w) == int:
n.append(w)
else:
s.append(w)
return ["".join(s), sum(n)]
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!")
March 21, 2024