diff --git a/ch03-lists-tuples/e09b4_even_odd_sums.py b/ch03-lists-tuples/e09b4_even_odd_sums.py index 3afc336..fd5d941 100755 --- a/ch03-lists-tuples/e09b4_even_odd_sums.py +++ b/ch03-lists-tuples/e09b4_even_odd_sums.py @@ -2,18 +2,11 @@ """Solution to chapter 3, exercise 9, beyond 4: even_odd_sums""" -def even_odd_sums(numbers): - """Takes a list of numbers, and returns a two-element -list containing the sum of the even elements and the -sum of the odd elements. -""" - evens = [] - odds = [] +# Write a function that takes a list or tuple of numbers. Return a two-element list, +# containing (respectively) the sum of the even-indexed numbers and the sum of +# the odd-indexed numbers. So calling the function as even_odd_sums([10, 20, +# 30, 40, 50, 60]), you’ll get back [90, 120]. - for one_number in numbers: - if one_number % 2: - odds.append(one_number) - else: - evens.append(one_number) - return [sum(evens), sum(odds)] +def even_odd_sums(any_type): + return [sum(any_type[::2]),sum(any_type[1::2])]