forked from hclivess/nado
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_ops.py
More file actions
61 lines (43 loc) · 1.43 KB
/
data_ops.py
File metadata and controls
61 lines (43 loc) · 1.43 KB
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
import random
import re
import sys
from pathlib import Path
def get_home():
return f"{Path.home()}/nado"
def check_traversal(to_check):
allowed = "^\w+$"
if not re.search(allowed, to_check):
raise ValueError(f"Traversal attack attempt with [{to_check}]")
def dict_to_val_list(some_dict) -> list:
return_list = []
for value in some_dict.values():
return_list.append(value)
return return_list
def sort_occurrence(some_list) -> list:
"""takes list of values, returns list with unique values sorted by occurrence"""
total = {value: some_list.count(value) for value in some_list}
sorted_total = sorted(total, key=total.get, reverse=True)
return sorted_total
def set_and_sort(entries: list) -> list:
sorted_entries = sorted(list(set(entries)))
return sorted_entries
def average(list_of_values) -> int:
total = 0
for value in list_of_values:
total = total + value
return int(total / len(list_of_values))
def sort_list_dict(entries) -> list:
clean_list = []
for entry in entries:
if entry not in clean_list:
clean_list.append(entry)
return clean_list
def get_byte_size(size_of) -> int:
return sys.getsizeof(repr(size_of))
def shuffle_dict(dictionary) -> dict:
items = list(dictionary.items())
random.shuffle(items)
shuffled_dict = {}
for key, value in items:
shuffled_dict[key] = value
return shuffled_dict