diff options
| author | Gustav Sörnäs <gusso230@student.liu.se> | 2020-02-05 16:56:42 +0100 |
|---|---|---|
| committer | Gustav Sörnäs <gusso230@student.liu.se> | 2020-02-05 16:56:42 +0100 |
| commit | 35c2c6787fb87e27544521ea915a602afe09ac3f (patch) | |
| tree | d6f8c976cae73bac7f462f13cd89df79f28a94a2 /upg2_3.py | |
| parent | bf125b50ddbd7550c757c716d736bc65ea1f0a25 (diff) | |
| download | tdde44-master.tar.gz | |
Diffstat (limited to 'upg2_3.py')
| -rw-r--r-- | upg2_3.py | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/upg2_3.py b/upg2_3.py new file mode 100644 index 0000000..619e852 --- /dev/null +++ b/upg2_3.py @@ -0,0 +1,68 @@ +def replace_periods_with_newlines(string_value): + str_list = list(string_value) + for i in range(len(string_value)): + if str_list[i] == ".": + str_list[i] = "\n" + return "".join(str_list) + +def replace_char_in_string(original_string, search_character, replacement): + str_list = list(original_string) + for i in range(len(str_list)): + if str_list[i] == search_character: + str_list[i] = replacement + return "".join(str_list) + +def reverse_string_for(string_value): + s = "" + for c in string_value[::-1]: + s += c + return s + +def reverse_string_while(string_value): + str_list = list(string_value) + l = [] + i = len(str_list)-1 + while i >= 0: + l.append(str_list[i]) + i -= 1 + return "".join(l) + +def get_five_first(value_list): + l = [] + for i in range(5): + l.append(value_list[i]) + return l + +def get_nfirst(value_list, n): + l = [] + for i in range(n): + l.append(value_list[i]) + return l + +def get_all_less_than(values, cutoff): + return list(filter(lambda n: n < cutoff, values)) + +def get_all_even(values): + return list(filter(lambda n: n % 2 == 0, values)) + +def get_all_divisible(values, divisor): + return list(filter(lambda n: n % divisor == 0, values)) + +def multiply_for_each(values, multiplier): + for i in range(len(values)): + values[i] *= multiplier + return values + +def insert_at_asc_place(values, new_value): + for i, val in enumerate(values): + if new_value < val: + values.insert(i, new_value) + return values + values.append(new_value) + return values + +def sort_asc(values): + sort = [] + for val in values: + insert_at_asc_place(sort, val) + return sort |
