-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhelpers.py
executable file
·68 lines (54 loc) · 1.57 KB
/
helpers.py
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
62
63
64
65
66
67
68
import string
class Helpers():
"""
Helper class with helpful methods
Utility type stuff. You know.
"""
def unique(self, text):
"""
Returns a list of unique elements
(Ie. this removes duplicates from a string)
:param text: string
:return: list
"""
output = []
for letter in text:
if letter not in output:
output.append(letter)
return output
def alphabet(self, type=None):
"""
Generates an alphabet, returns either
a string or a list
:param type: string (default) or list
:return: mixed
"""
if type is None or type == "string":
alpha = string.ascii_uppercase
elif type == "list":
alpha = list(string.ascii_uppercase)
return alpha
def polybius_square(self):
"""
generate polybius square
Returns a dictionary of letters (key) with their
corresponding values per a basic polybius square
Ie. {'A': [1, 1], 'B': [2, 1], 'C': [3, 1]...
:return: dict
"""
alphabet = self.alphabet()
x = 1
y = 1
polybius = {}
for letter in alphabet:
polybius[letter] = [x, y]
# I & J share the same key, so
# don't increment the count on I
if not letter == "I":
x += 1
# reset x when it hits 5,
# also increment Y by 1
if x > 5:
x = 1
y += 1
return polybius