-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.py
More file actions
27 lines (21 loc) · 883 Bytes
/
utils.py
File metadata and controls
27 lines (21 loc) · 883 Bytes
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
from collections import Counter
# Restructure the table as the list of its columns, ignoring the headers
def parse_table(table, num_cols, num_headers):
return [[row[i] for row in table[num_headers:]] for i in range(0, num_cols)]
# Convert a table into a bag of tuples
def to_bag(table):
counter = dict()
tuples = [tuple([col[i] for col in table]) for i in range(0, len(table[0]))]
for i in range(0, len(tuples)):
if tuples[i] in counter:
counter[tuples[i]] += 1
else:
counter[tuples[i]] = 0
tuples[i] += (counter[tuples[i]],)
return set(tuples)
# Convert a table into a bag of tuples using counter objects
def to_bag_counter(table):
counter = Counter()
for t in [tuple([col[i] for col in table]) for i in range(0, len(table[0]))]:
counter[t] += 1
return counter