假期结束了,准备好开始学习了吗?今天给大家带来一道列表的题目,快来看看你会不会解。前几天有小伙伴问了一个Python列表的问题,这里拿出来给大家分享下,一起学习下。
题目如下:
Python学习交流Q群:903971231###
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). Return 0 for no numbers.
summer_69([1, 3, 5]) --> 9
summer_69([4, 5, 6, 7, 8, 9]) --> 9
summer_69([2, 1, 6, 9, 11]) --> 14
嗯,英文提问,看上去有点懵!
02
解决过程
这个题目一看上去还是有点难度的,思路方面是个问题,值得大家探讨了一发。
给出了几个可行的思路。
1.解答
这里给出了解答,如下所示:
def summer69(arr):
index_of_6 = arr.index(6)
index_of_9 = len(arr) - arr[::