0
Which is the better way to solve this problem?
Which is the better way to solve this problem? Problem: SUMMER OF '69: Return the sum of the numbers in the array, except ignore sections of numbers starting with a 6 and extending to the next 9 (every 6 will be followed by at least one 9). Example: summer_69([2, 1, 6, 9, 11]) --> 14 Solution 1: https://code.sololearn.com/cetiTbYAsYn3 Solution 2: https://code.sololearn.com/czwaA6xRaFum
2 Réponses
+ 1
And I prefer the solution 1.
+ 1
def summer_69(arr):
return sum([
a
if (6 not in arr)
or (arr.index(a) < arr.index(6))
or (arr.index(a) > arr.index(9))
else 0
for a in arr
])