aboutsummaryrefslogtreecommitdiff
path: root/challenge-289/luca-ferrari/python/ch-2.py
blob: 30c16a5e2a0d0d738c9c46bb96d1326cbce29f62 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!python

#
# Perl Weekly Challenge 289
# Task 2
#
# See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-289>
#

import sys
import random

# task implementation
# the return value will be printed
def task_2( words ):
    new_words = []

    for word in words:
        current_word = []
        current_word.append( word[ 0 ] )

        last_index = len( word ) - 1
        while not str.isalpha( word[ last_index ] ) and not str.isdigit( word[ last_index ] ):
            last_index -= 1

        shuffling = list( map( str, word[ 1 : last_index ] ) )
        random.shuffle( shuffling )
        for r in shuffling:
            current_word.append( r )

        current_word.append( word[ last_index : ] )
        new_words.append( ''.join( current_word ) )

    return new_words



# invoke the main without the command itself
if __name__ == '__main__':
    print( task_2( sys.argv[ 1: ] ) )