Skipping elements in a List Python

后端 未结 7 1649
隐瞒了意图╮
隐瞒了意图╮ 2021-01-17 13:28

I\'m new to programming and I\'m trying to do the codingbat.com problems to start. I came across this problem:

Given an array calculate the sum except when there is

7条回答
  •  有刺的猬
    2021-01-17 14:09

    def skipAndAddFun(inputVal, skipList):
       sum = 0
       for i in inputVal:
            if not i in skipList:
                sum += i
        return sum
    

    Usage:

    skipAndAddFun([1,2,13,5,1], [13, 5])
    4
    

    This simple function will be a generic solution for your question.

提交回复
热议问题