aboutsummaryrefslogtreecommitdiff
path: root/challenge-278/luca-ferrari/python
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-278/luca-ferrari/python')
-rw-r--r--challenge-278/luca-ferrari/python/ch-1.py30
-rw-r--r--challenge-278/luca-ferrari/python/ch-2.py33
2 files changed, 63 insertions, 0 deletions
diff --git a/challenge-278/luca-ferrari/python/ch-1.py b/challenge-278/luca-ferrari/python/ch-1.py
new file mode 100644
index 0000000000..c2a980ed76
--- /dev/null
+++ b/challenge-278/luca-ferrari/python/ch-1.py
@@ -0,0 +1,30 @@
+#!python
+
+#
+# Perl Weekly Challenge 278
+# Task 1
+#
+# See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-278>
+#
+
+import sys
+import re
+
+# task implementation
+# the return value will be printed
+def task_1( args ):
+ sorted_words = {}
+ pattern = re.compile( "^([a-zA-Z]+)(\\d)+$" )
+
+ for w in args:
+ m = pattern.match( w )
+ sorted_words[ str( m.group( 2 ) ) ] = m.group( 1 )
+
+ sorted_words = dict( sorted( sorted_words.items() ) )
+ return ' '.join( sorted_words.values() )
+
+
+
+# invoke the main without the command itself
+if __name__ == '__main__':
+ print( task_1( sys.argv[ 1: ] ) )
diff --git a/challenge-278/luca-ferrari/python/ch-2.py b/challenge-278/luca-ferrari/python/ch-2.py
new file mode 100644
index 0000000000..f82d4cf753
--- /dev/null
+++ b/challenge-278/luca-ferrari/python/ch-2.py
@@ -0,0 +1,33 @@
+#!python
+
+#
+# Perl Weekly Challenge 278
+# Task 2
+#
+# See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-278>
+#
+
+import sys
+
+# task implementation
+# the return value will be printed
+def task_2( args ):
+ word = args[ 0 ]
+ c = args[ 1 ]
+
+ if not c in word:
+ return word
+
+ left = []
+
+ for x in word:
+ left.append( x )
+ if x == c:
+ break
+
+ return ''.join( list( sorted( left ) ) ) + word[ len( left ) : len( word ) ]
+
+
+# invoke the main without the command itself
+if __name__ == '__main__':
+ print( task_2( sys.argv[ 1: ] ) )