Ad
Code
Diff
  • def add(s, o):
        return {
            0: sum(int(c) for c in s),
            1: sum(int(c) for c in s if int(c)%2),
            2: sum(int(c) for c in s if not(int(c)%2))
        }.get(o, 0);
    • def add(s, o):
    • if o == 0: return sum(int(c) for c in s)
    • elif o == 1: return sum(int(c) for c in s if int(c)%2)
    • elif o == 2: return sum(int(c) for c in s if not(int(c)%2))
    • else: return 0
    • return {
    • 0: sum(int(c) for c in s),
    • 1: sum(int(c) for c in s if int(c)%2),
    • 2: sum(int(c) for c in s if not(int(c)%2))
    • }.get(o, 0);