-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtility.py
More file actions
35 lines (33 loc) · 1.14 KB
/
Utility.py
File metadata and controls
35 lines (33 loc) · 1.14 KB
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
def getLinesFromFile(path):
with open(path) as input:
return [''.join(filter(lambda c: c != '\n', s)) for s in input.readlines()]
def maxBy(elements, selector = None):
elementList = list(elements)
highestElement = elementList[0]
highest = elementList[0] if selector == None else selector(elementList[0])
if (selector == None):
for e in elementList:
if (e > highest):
highest = e
highestElement = e
else:
for e in elementList:
if (selector(e) > highest):
highest = selector(e)
highestElement = e
return highestElement
def minBy(elements, selector = None):
elementList = list(elements)
lowestElement = elementList[0]
lowest = elementList[0] if selector == None else selector(elementList[0])
if(selector == None):
for e in elementList:
if (e < lowest):
lowest = e
lowestElement = e
else:
for e in elementList:
if (selector(e) < lowest):
lowest = selector(e)
lowestElement = e
return lowestElement