diff options
| author | 冯昶 <seaker@qq.com> | 2020-09-21 14:20:42 +0800 |
|---|---|---|
| committer | 冯昶 <seaker@qq.com> | 2020-09-21 14:20:42 +0800 |
| commit | bca0c362c212fc0dadc5ed7d9a5e4fa1aece4bfb (patch) | |
| tree | 877181cfde26b706346d3468269e4674d75da772 /challenge-078/lubos-kolouch/python/ch-2.py | |
| parent | ec09b571a6f2186fec8870a071a8d5d38596c850 (diff) | |
| parent | 5ac16ac7e9826137e0da5597e954f4992c66205d (diff) | |
| download | perlweeklychallenge-club-bca0c362c212fc0dadc5ed7d9a5e4fa1aece4bfb.tar.gz perlweeklychallenge-club-bca0c362c212fc0dadc5ed7d9a5e4fa1aece4bfb.tar.bz2 perlweeklychallenge-club-bca0c362c212fc0dadc5ed7d9a5e4fa1aece4bfb.zip | |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-078/lubos-kolouch/python/ch-2.py')
| -rw-r--r-- | challenge-078/lubos-kolouch/python/ch-2.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/challenge-078/lubos-kolouch/python/ch-2.py b/challenge-078/lubos-kolouch/python/ch-2.py new file mode 100644 index 0000000000..c1be12853b --- /dev/null +++ b/challenge-078/lubos-kolouch/python/ch-2.py @@ -0,0 +1,35 @@ +#!/bin/env python +""" https://perlweeklychallenge.org/blog/perl-weekly-challenge-078/ + Task 2 + Left Rotation + 19.9.2020 Lubos Kolouch """ + + +class ListRotator: + """ Rotate the array based on list of elems """ + + def __init__(self, arr: list(), elems: list()): + self.arr = arr + self.elems = elems + + def rotate_arr(self, first: int): + """ Rotate the array so that passed elem is first """ + + return self.arr[first:] + self.arr[0:first] + + def process_offset(self): + """ Process the list of elems for rotation """ + + output = list() + + for elem in self.elems: + output.append(self.rotate_arr(elem)) + + return output + + +test_list = ListRotator(arr=[10, 20, 30, 40, 50], elems=[3, 4]) +assert test_list.process_offset() == [[40, 50, 10, 20, 30], [50, 10, 20, 30, 40]] + +test_list = ListRotator(arr=[7, 4, 2, 6, 3], elems=[1, 3, 4]) +assert test_list.process_offset() == [[4, 2, 6, 3, 7], [6, 3, 7, 4, 2], [3, 7, 4, 2, 6]] |
