29 lines
596 B
Python
29 lines
596 B
Python
#
|
|
# misc.py
|
|
# Various helper functions
|
|
|
|
def confirm(question):
|
|
answer = ''
|
|
while answer not in ('y','n'):
|
|
print(question, end=' ')
|
|
answer = input().lower()
|
|
return answer == 'y'
|
|
|
|
def exists(func,list):
|
|
return len(list(filter(func,list))) > 0
|
|
|
|
def forall(func,list):
|
|
return len(list(filter(func,list))) == len(list)
|
|
|
|
def uniq(li):
|
|
result = []
|
|
for elem in li:
|
|
if (not elem in result):
|
|
result.append(elem)
|
|
return result
|
|
|
|
# Return a sorted copy of a list
|
|
def sorted(li):
|
|
result = li[:]
|
|
result.sort()
|
|
return result |