diff options
| author | Mohammad Sajid Anwar <mohammad.anwar@yahoo.com> | 2025-02-03 15:25:40 +0000 |
|---|---|---|
| committer | Mohammad Sajid Anwar <mohammad.anwar@yahoo.com> | 2025-02-03 15:25:40 +0000 |
| commit | 874f068f6c61fb234a2be113b1831a132507f491 (patch) | |
| tree | 8582b4bfc0d64d78cd5bec1b1eb59cb69955a2cf /challenge-307/eric-cheung/python | |
| parent | 6b15d08f9a9014f7595de9d9610826eeeff5b9bb (diff) | |
| download | perlweeklychallenge-club-874f068f6c61fb234a2be113b1831a132507f491.tar.gz perlweeklychallenge-club-874f068f6c61fb234a2be113b1831a132507f491.tar.bz2 perlweeklychallenge-club-874f068f6c61fb234a2be113b1831a132507f491.zip | |
- Added solutions by Eric Cheung.
Diffstat (limited to 'challenge-307/eric-cheung/python')
| -rwxr-xr-x | challenge-307/eric-cheung/python/ch-1.py | 10 | ||||
| -rwxr-xr-x | challenge-307/eric-cheung/python/ch-2.py | 25 |
2 files changed, 35 insertions, 0 deletions
diff --git a/challenge-307/eric-cheung/python/ch-1.py b/challenge-307/eric-cheung/python/ch-1.py new file mode 100755 index 0000000000..4929e89e49 --- /dev/null +++ b/challenge-307/eric-cheung/python/ch-1.py @@ -0,0 +1,10 @@ +
+## arrInts = [5, 2, 4, 3, 1] ## Example 1
+## arrInts = [1, 2, 1, 1, 3] ## Example 2
+arrInts = [3, 1, 3, 2, 3] ## Example 3
+
+arrSorted = sorted(arrInts)
+
+arrOutput = [nIndx for nIndx, (nOrig, nSort) in enumerate(zip(arrInts, arrSorted)) if nOrig != nSort]
+
+print (arrOutput)
diff --git a/challenge-307/eric-cheung/python/ch-2.py b/challenge-307/eric-cheung/python/ch-2.py new file mode 100755 index 0000000000..6d867fd239 --- /dev/null +++ b/challenge-307/eric-cheung/python/ch-2.py @@ -0,0 +1,25 @@ +
+## Ref.:
+## https://www.geeksforgeeks.org/python-sorted-check-two-strings-anagram-not/
+
+def IsAnagrams (strInput_01, strInput_02):
+ return (sorted(strInput_01) == sorted(strInput_02))
+
+## arrWords = ["acca", "dog", "god", "perl", "repl"] ## Example 1
+arrWords = ["abba", "baba", "aabb", "ab", "ab"] ## Example 2
+
+## arrIndxToDel = []
+## for nIndx in range(len(arrWords) - 2, -1, -1):
+ ## if IsAnagrams (arrWords[nIndx], arrWords[nIndx + 1]):
+ ## arrIndxToDel.append(nIndx)
+
+arrIndxToDel = [nIndx for nIndx in range(len(arrWords) - 2, -1, -1) if IsAnagrams (arrWords[nIndx], arrWords[nIndx + 1])]
+
+## print (arrIndxToDel)
+
+## for nIndx in arrIndxToDel:
+ ## del arrWords[nIndx]
+
+## print (len(arrWords))
+
+print (len(arrWords) - len(arrIndxToDel))
|
