aboutsummaryrefslogtreecommitdiff
blob: a6ebb1b7724c0576a59d1e735c748704d59528f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
"""Miscellaneous utility functions"""

def list_add(dst, src):
    """
    Extends the target list with a scalar, or contents of the given list
    """
    if isinstance(src, list):
        dst.extend(src)
    else:
        dst.append(src)


def pivot(string, idx, keep_pivot=False):
    """
    A function to split a string in two, pivoting at string[idx].
    If keep_pivot is set, the pivot character is included in the second string.
    Alternatively, it is omitted.
    """
    if keep_pivot:
        return (string[:idx], string[idx:])
    else:
        return (string[:idx], string[idx+1:])