Add matching brackets file properly
This commit is contained in:
parent
b8252195f1
commit
e5ad06fc22
@ -1,35 +0,0 @@
|
|||||||
class NoSuchStudentException(Exception):
|
|
||||||
pass
|
|
||||||
|
|
||||||
class Garden:
|
|
||||||
def __init__(self, diagram, students=None):
|
|
||||||
self.diagram = diagram
|
|
||||||
if students is None:
|
|
||||||
self.students = [
|
|
||||||
"Alena", "Boris", "Cyril", "Daniel", "Eva", "František",
|
|
||||||
"Gitka", "Helena", "Ivana", "Jozef", "Karol", "Ladislav"
|
|
||||||
]
|
|
||||||
else:
|
|
||||||
self.students = sorted(students)
|
|
||||||
|
|
||||||
self.plant_names = {
|
|
||||||
"G": "Tráva",
|
|
||||||
"C": "Ďatelina",
|
|
||||||
"R": "Reďkovky",
|
|
||||||
"V": "Fialky"
|
|
||||||
}
|
|
||||||
|
|
||||||
def plants(self, student):
|
|
||||||
if student not in self.students:
|
|
||||||
raise NoSuchStudentException("Student not found")
|
|
||||||
|
|
||||||
index = self.students.index(student)
|
|
||||||
start = index * 2
|
|
||||||
|
|
||||||
rows = self.diagram.splitlines()
|
|
||||||
row1 = rows[0]
|
|
||||||
row2 = rows[1]
|
|
||||||
|
|
||||||
letters = row1[start:start+2] + row2[start:start+2]
|
|
||||||
|
|
||||||
return [self.plant_names[char] for char in letters]
|
|
||||||
@ -6,9 +6,9 @@ def append(list1, list2):
|
|||||||
pusti.append(exc)
|
pusti.append(exc)
|
||||||
return pusti
|
return pusti
|
||||||
|
|
||||||
def concat(list):
|
def concat(lists):
|
||||||
pusti = []
|
pusti = []
|
||||||
for gns in list:
|
for gns in lists:
|
||||||
pusti.extend(gns)
|
pusti.extend(gns)
|
||||||
return pusti
|
return pusti
|
||||||
|
|
||||||
@ -28,24 +28,20 @@ def append(list1, list2):
|
|||||||
def map(function, list):
|
def map(function, list):
|
||||||
pusti = []
|
pusti = []
|
||||||
for gns in list:
|
for gns in list:
|
||||||
function(gns)
|
|
||||||
pusti.append(function(gns))
|
pusti.append(function(gns))
|
||||||
return pusti
|
return pusti
|
||||||
|
|
||||||
def foldl(function, accumulator, initial):
|
def foldl(function, list, initial):
|
||||||
accumulator = initial
|
accumulator = initial
|
||||||
for gns in list:
|
for gns in list:
|
||||||
accumulator = function(accumulator, gns)
|
accumulator = function(accumulator, gns)
|
||||||
return accumulator
|
return accumulator
|
||||||
|
|
||||||
def foldr(function, initial, acc):
|
def foldr(function, list, initial):
|
||||||
acc = initial
|
acc = initial
|
||||||
for gns in list[::-1]:
|
for gns in list[::-1]:
|
||||||
acc = function(gns, acc)
|
acc = function(gns, acc)
|
||||||
return acc
|
return acc
|
||||||
|
|
||||||
def reverse(list):
|
def reverse(list):
|
||||||
pusti = []
|
return list[::-1]
|
||||||
for gns in list:
|
|
||||||
pusti.append(gns)
|
|
||||||
return pusti[::-1]
|
|
||||||
Loading…
Reference in New Issue
Block a user