summaryrefslogtreecommitdiffstats
path: root/upg2_3.py
blob: 619e852633c84e55edd2735a31a27a8fb1ec0234 (plain) (blame)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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