-
Notifications
You must be signed in to change notification settings - Fork 1
/
Entry.py
66 lines (44 loc) · 1.56 KB
/
Entry.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
class Entry():
def __init__(self):
"""Basic info each entry holds."""
self.player = ""
self.guessed_player = False
self.artist = ""
self.blank_artist = ""
self.song = ""
self.blank_song = ""
def findIndexes(self, word, letter):
"""
Iterates over a word and returns a list with the positions in
which a letter apears on it.
"""
index = 0
index_list = []
for character in word:
if character == letter:
index_list.append(index)
index += 1
return index_list
def replaceLetter(self, name, letter, replacing_name):
"""
When a guessed letter is valid, all instances of it have
to be replaced.
"""
index_list = self.findIndexes(name, letter)
# Since strings are immutable, we need to transform it into a list
replacing_name = list(replacing_name)
if index_list != []:
for index in index_list:
replacing_name[index] = letter
# We put it as a string back again
return "".join(replacing_name)
def replaceWords(self, replacing_name, guess, index):
"""
Assume this won't go out of index range. Please.
"""
replacing_name = list(replacing_name)
guess = list(guess)
for character in guess:
replacing_name[index] = character
index += 1
return "".join(replacing_name)