-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathgenerator.py
More file actions
38 lines (28 loc) · 801 Bytes
/
generator.py
File metadata and controls
38 lines (28 loc) · 801 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
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env python
import re
from typing import List, Dict
def padding(str, p=' ', remove_empty_lines=True):
"""
normalize newlines
remove leading and trailing spaces
collapse spaces
collapse newlines
pad lines
"""
str = re.sub(r'[ \t]+\n', '\n', str)
if remove_empty_lines:
str = str.replace('\n\n', '\n')
str = str.replace('\n\n', '\n')
str = p + str.replace('\n', '\n' + p)
return str
def filterIndex(index: List[Dict], group: str):
filtered = []
for item in index:
if item['group'] == group:
filtered.append(item)
return filtered
def groupList(index: List[Dict]):
groups = []
for item in index:
groups.append(item['group'])
return list(set(groups))