From 153f22e7dc6b1860d8561da89efeeefdfa83eab9 Mon Sep 17 00:00:00 2001 From: Mohammad Sajid Anwar Date: Tue, 5 Aug 2025 11:55:34 +0100 Subject: - Added solutions by Lukas Mai. - Added solutions by E. Choroba. --- challenge-333/eric-cheung/python/ch-2.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100755 challenge-333/eric-cheung/python/ch-2.py (limited to 'challenge-333/eric-cheung/python/ch-2.py') 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)]) -- cgit