aboutsummaryrefslogtreecommitdiff
path: root/challenge-266/luca-ferrari/python/ch-1.py
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-04-23 16:34:40 +0100
committerGitHub <noreply@github.com>2024-04-23 16:34:40 +0100
commit705fa6a401e9ecd089fb55e0cb45df905bbfd1bf (patch)
tree605445722d80e3486bac114ac184c4bec15baecc /challenge-266/luca-ferrari/python/ch-1.py
parent59d11166c24beb75c69862f9916592a4fadfb8ce (diff)
parent5dba324368d526b878978f60d55ae1db3b795804 (diff)
downloadperlweeklychallenge-club-705fa6a401e9ecd089fb55e0cb45df905bbfd1bf.tar.gz
perlweeklychallenge-club-705fa6a401e9ecd089fb55e0cb45df905bbfd1bf.tar.bz2
perlweeklychallenge-club-705fa6a401e9ecd089fb55e0cb45df905bbfd1bf.zip
Merge pull request #9974 from fluca1978/PWC266
PWC 266
Diffstat (limited to 'challenge-266/luca-ferrari/python/ch-1.py')
-rw-r--r--challenge-266/luca-ferrari/python/ch-1.py52
1 files changed, 52 insertions, 0 deletions
diff --git a/challenge-266/luca-ferrari/python/ch-1.py b/challenge-266/luca-ferrari/python/ch-1.py
new file mode 100644
index 0000000000..3d5f542714
--- /dev/null
+++ b/challenge-266/luca-ferrari/python/ch-1.py
@@ -0,0 +1,52 @@
+#!python
+
+#
+# Perl Weekly Challenge 266
+# Task 1
+#
+# See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-266>
+#
+
+import sys
+
+# task implementation
+# the return value will be printed
+def task_1( args ):
+ left = args[ 0 ]
+ right = args[ 1 ]
+
+ bag_left = {}
+ bag_right = {}
+
+ # classify
+ for w in left.split():
+ c = 1
+ w = w.lower()
+ if w in bag_left:
+ c += bag_left[ w ]
+
+ bag_left[ w ] = c
+
+ for w in right.split():
+ c = 1
+ w = w.lower()
+ if w in bag_right:
+ c += bag_right[ w ]
+
+ bag_right[ w ] = c
+
+ words = []
+ for w in bag_left:
+ if bag_left[ w ] == 1 and not w in bag_right:
+ words.append( w )
+
+ for w in bag_right:
+ if bag_right[ w ] == 1 and not w in bag_left:
+ words.append( w )
+
+ return words
+
+
+# invoke the main without the command itself
+if __name__ == '__main__':
+ print( task_1( sys.argv[ 1: ] ) )