-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlevel25.py
More file actions
25 lines (16 loc) · 716 Bytes
/
level25.py
File metadata and controls
25 lines (16 loc) · 716 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# Given an array of integers, replace all the occurrences of elemToReplace with substitutionElem.
def solution(inputArray, elemToReplace, substitutionElem):
for i in range(len(inputArray)):
if inputArray[i]==elemToReplace:
inputArray[i]=substitutionElem
return inputArray
# pretty
# def solution(inputArray, elemToReplace, substitutionElem):
# return [substitutionElem if x==elemToReplace else x for x in inputArray]
# alt solution
# def solution(inputArray, elemToReplace, substitutionElem):
# for i in range(len(inputArray)):
# if inputArray[i]==elemToReplace:
# inputArray[i]=substitutionElem
# continue
# return inputArray