aboutsummaryrefslogtreecommitdiff
path: root/challenge-333/eric-cheung/python/ch-2.py
blob: 7e96b1df40cb2157124c13ec4b6b0bcf166bc642 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
## arrInt = [1, 0, 2, 3, 0, 4, 5, 0]  ## Example 1
## arrInt = [1, 2, 3]  ## Example 2
## arrInt = [1, 2, 3, 0]  ## Example 3
## arrInt = [0, 0, 1, 2]  ## Example 4
arrInt = [1, 2, 0, 3, 4]  ## Example 5

arrOut = arrInt[:]

arrZeroPos = [nPos for nPos, nElem in enumerate(arrInt) if nElem == 0]

if len(arrZeroPos) == 0:
    print (arrOut)
else:
    for nPos in arrZeroPos[::-1]:
        arrOut.insert(nPos, 0)
    print (arrOut[:len(arrInt)])