

def arrayReplace(inputArray, elemToReplace, substitutionElem):
    pass


def main():
    pass


if __name__ == '__main__':
    main()



def arrayReplace(inputArray, elemToReplace, substitutionElem):
    return [x if x != elemToReplace else substitutionElem for x in inputArray]


def main():
    tests = [
        [[1, 2, 1], 1, 3, [3, 2, 3]],
        [[1, 2, 3, 4, 5], 3, 0, [1, 2, 0, 4, 5]],
        [[1, 1, 1], 1, 10, [10, 10, 10]]
    ]

    for t in tests:
        res = arrayReplace(t[0], t[1], t[2])
        if t[3] == res:
            print("PASSED: arrayReplace({}, {}, {}) returned {}"
                  .format(t[0], t[1], t[2], res))
        else:
            print("FAILED: arrayReplace({}, {}, {}) returned {}, should have returned {}"
                  .format(t[0], t[1], t[2], res, t[3]))


if __name__ == '__main__':
    main()

Solve Code Fights array replace problem
Solve Code Fights array replace problem

  
  
  def arrayReplace(inputArray, elemToReplace, substitutionElem):
-     pass
+     return [x if x != elemToReplace else substitutionElem for x in inputArray]
  
  
  def main():
-     pass
+     tests = [
+         [[1, 2, 1], 1, 3, [3, 2, 3]],
+         [[1, 2, 3, 4, 5], 3, 0, [1, 2, 0, 4, 5]],
+         [[1, 1, 1], 1, 10, [10, 10, 10]]
+     ]
+ 
+     for t in tests:
+         res = arrayReplace(t[0], t[1], t[2])
+         if t[3] == res:
+             print("PASSED: arrayReplace({}, {}, {}) returned {}"
+                   .format(t[0], t[1], t[2], res))
+         else:
+             print("FAILED: arrayReplace({}, {}, {}) returned {}, should have returned {}"
+                   .format(t[0], t[1], t[2], res, t[3]))
  
  
  if __name__ == '__main__':
      main()
  
Solve Code Fights array replace problem
## Code Before:


def arrayReplace(inputArray, elemToReplace, substitutionElem):
    pass


def main():
    pass


if __name__ == '__main__':
    main()

## Instruction:
Solve Code Fights array replace problem
## Code After:


def arrayReplace(inputArray, elemToReplace, substitutionElem):
    return [x if x != elemToReplace else substitutionElem for x in inputArray]


def main():
    tests = [
        [[1, 2, 1], 1, 3, [3, 2, 3]],
        [[1, 2, 3, 4, 5], 3, 0, [1, 2, 0, 4, 5]],
        [[1, 1, 1], 1, 10, [10, 10, 10]]
    ]

    for t in tests:
        res = arrayReplace(t[0], t[1], t[2])
        if t[3] == res:
            print("PASSED: arrayReplace({}, {}, {}) returned {}"
                  .format(t[0], t[1], t[2], res))
        else:
            print("FAILED: arrayReplace({}, {}, {}) returned {}, should have returned {}"
                  .format(t[0], t[1], t[2], res, t[3]))


if __name__ == '__main__':
    main()
