diff options
| author | Mohammad Sajid Anwar <mohammad.anwar@yahoo.com> | 2025-08-05 11:55:34 +0100 |
|---|---|---|
| committer | Mohammad Sajid Anwar <mohammad.anwar@yahoo.com> | 2025-08-05 11:55:34 +0100 |
| commit | 153f22e7dc6b1860d8561da89efeeefdfa83eab9 (patch) | |
| tree | 01b2386dbff82575e1de7ec3c1a208295b046fd1 /challenge-333/eric-cheung/python/ch-2.py | |
| parent | 4869914836ceba6b2a3f0b2bd762cc5764d46dfb (diff) | |
| download | perlweeklychallenge-club-153f22e7dc6b1860d8561da89efeeefdfa83eab9.tar.gz perlweeklychallenge-club-153f22e7dc6b1860d8561da89efeeefdfa83eab9.tar.bz2 perlweeklychallenge-club-153f22e7dc6b1860d8561da89efeeefdfa83eab9.zip | |
- Added solutions by Lukas Mai.
- Added solutions by E. Choroba.
Diffstat (limited to 'challenge-333/eric-cheung/python/ch-2.py')
| -rwxr-xr-x | challenge-333/eric-cheung/python/ch-2.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/challenge-333/eric-cheung/python/ch-2.py b/challenge-333/eric-cheung/python/ch-2.py new file mode 100755 index 0000000000..7e96b1df40 --- /dev/null +++ b/challenge-333/eric-cheung/python/ch-2.py @@ -0,0 +1,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)])
|
