-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathletterBag.py
30 lines (25 loc) · 1.07 KB
/
letterBag.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
'''contains all the 100 letters'''
import random
class letterBag():
def __init__(self):
letterDict = {'A' : 9, 'B' : 2, 'C' : 2, 'D' : 3, 'E' : 12, 'F' : 2, 'G' : 3, 'H' : 2,
'I' : 9, 'J' : 1, 'K' : 1, 'L' : 4, 'M' : 2, 'N' : 6, 'O' : 8, 'P' : 2,
'Q' : 1, 'R' : 6, 'S' : 4, 'T' : 6, 'U' : 3, 'V' : 2, 'W' : 2, 'X' : 1,
'Y' : 2, 'Z' : 1}
self.letterBag = []
for key in letterDict.keys():
for _ in range(letterDict[key]):
self.letterBag.append(key)
def removeLetters(self, num):
removedLetters = ''
if num < len(self.letterBag):
for _ in range(num):
x = random.random()
index = int(x*len(self.letterBag) // 1)
removedLetters += self.letterBag[index]
self.letterBag.pop(index)
else:
for letter in self.letterBag:
removedLetters += letter
self.letterBag = []
return removedLetters