Skip to content

Common

Common functions.

intsec

intsec(list1, list2)

Simple intesection of two lists.

Parameters:

Name Type Description Default
list1 list

list1

required
list2 list

list2

required

Returns:

Name Type Description
list list

intersection of lists

Source code in src/common.py
 6
 7
 8
 9
10
11
12
13
14
15
16
def intsec(list1: list, list2: list) -> list:
    """Simple intesection of two lists.

    Args:
        list1 (list): list1
        list2 (list): list2

    Returns:
        list (list): intersection of lists
    """
    return list(set.intersection(set(list1), set(list2)))

diff

diff(list1, list2)

Simple difference of items in list2 from list1.

Parameters:

Name Type Description Default
list1 list

list1

required
list2 list

list2

required

Returns:

Name Type Description
list list

difference of lists

Source code in src/common.py
19
20
21
22
23
24
25
26
27
28
29
def diff(list1: list, list2: list) -> list:
    """Simple difference of items in list2 from list1.

    Args:
        list1 (list): list1
        list2 (list): list2

    Returns:
        list (list): difference of lists
    """
    return list(set(list1).difference(set(list2)))

json_load

json_load(file_loc)

Helper function to open/close json file, otherwise the python outputs warning that the file remains opened

Parameters:

Name Type Description Default
file_loc str

location of the file

required

Returns:

Name Type Description
content dict

content of json file, usually dictionary

Source code in src/common.py
32
33
34
35
36
37
38
39
40
41
42
43
44
def json_load(file_loc: str):
    """Helper function to open/close json file,
    otherwise the python outputs warning that the file remains opened

    Args:
        file_loc (str): location of the file

    Returns:
        content (dict): content of json file, usually dictionary
    """
    with open(file_loc, "rb") as f:
        content = json.load(f)
    return content

json_dump

json_dump(file_loc, content)

Helper function to open/close json file and dump content into it, otherwise the python outputs warning that the file remains opened

Parameters:

Name Type Description Default
file_loc str

location of the file

required
content object

data that will be saved to json, usually dictionary

required
Source code in src/common.py
47
48
49
50
51
52
53
54
55
56
def json_dump(file_loc: str, content: object):
    """Helper function to open/close json file and dump content into it,
    otherwise the python outputs warning that the file remains opened

    Args:
        file_loc (str): location of the file
        content (object): data that will be saved to json, usually dictionary
    """
    with open(file_loc, "wb") as f:
        json.dump(content, f)

dill_load

dill_load(file_loc)

Helper function to open/close dill file, otherwise the python outputs warning that the file remains opened

Parameters:

Name Type Description Default
file_loc str

location of the file

required

Returns:

Name Type Description
content dict

content of dill file, usually dictionary

Source code in src/common.py
59
60
61
62
63
64
65
66
67
68
69
70
71
def dill_load(file_loc: str):
    """Helper function to open/close dill file,
    otherwise the python outputs warning that the file remains opened

    Args:
        file_loc (str): location of the file

    Returns:
        content (dict): content of dill file, usually dictionary
    """
    with open(file_loc, "rb") as f:
        content = dill.load(f)
    return content

dill_dump

dill_dump(file_loc, content)

Helper function to open/close dill file and dump content into it, otherwise the python outputs warning that the file remains opened

Parameters:

Name Type Description Default
file_loc str

location of the file

required
content object

data that will be saved to dill, usually dictionary

required
Source code in src/common.py
74
75
76
77
78
79
80
81
82
83
def dill_dump(file_loc: str, content: object):
    """Helper function to open/close dill file and dump content into it,
    otherwise the python outputs warning that the file remains opened

    Args:
        file_loc (str): location of the file
        content (object): data that will be saved to dill, usually dictionary
    """
    with open(file_loc, "wb") as f:
        dill.dump(content, f)