diff options
| author | Lubos Kolouch <lubos@kolouch.net> | 2020-08-16 14:01:10 +0200 |
|---|---|---|
| committer | Lubos Kolouch <lubos@kolouch.net> | 2020-08-16 14:01:10 +0200 |
| commit | a5da5d091bc987ef2cd89a641a473066b0b05cbb (patch) | |
| tree | 3d53a8f2358231418123256b2e9b2524b98365a8 | |
| parent | 8543f8965310f3f234ecf858f1d1f455eff27652 (diff) | |
| download | perlweeklychallenge-club-a5da5d091bc987ef2cd89a641a473066b0b05cbb.tar.gz perlweeklychallenge-club-a5da5d091bc987ef2cd89a641a473066b0b05cbb.tar.bz2 perlweeklychallenge-club-a5da5d091bc987ef2cd89a641a473066b0b05cbb.zip | |
Challenge 2 Python LK
| -rwxr-xr-x | challenge-073/lubos-kolouch/python/ch-2.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/challenge-073/lubos-kolouch/python/ch-2.py b/challenge-073/lubos-kolouch/python/ch-2.py new file mode 100755 index 0000000000..ebf988621b --- /dev/null +++ b/challenge-073/lubos-kolouch/python/ch-2.py @@ -0,0 +1,29 @@ +#! /usr/bin/env python +""" Perl weekly challenge 073 + https://perlweeklychallenge.org/blog/perl-weekly-challenge-073/ Task 2 """ + + +def get_smallest(arr): + """Write a script to create an array that represents the + smallest element to the left of each corresponding index. + If none found then use 0. """ + + return_array = list() + return_array.append(0) + + my_min = arr[0] + + for i in range(1, len(arr)): + if my_min < arr[i]: + return_array.append(my_min) + else: + return_array.append(0) + + if arr[i] < my_min: + my_min = arr[i] + + return return_array + + +assert get_smallest([7, 8, 3, 12, 10]) == [0, 7, 0, 3, 3] +assert get_smallest([4, 6, 5]) == [0, 4, 4] |
