scyther/scripts/if2spdl/misc.py

29 lines
596 B
Python
Raw Normal View History

2005-11-16 19:07:19 +00:00
#
# misc.py
# Various helper functions
def confirm(question):
answer = ''
while answer not in ('y','n'):
2020-10-28 14:13:02 +00:00
print(question, end=' ')
answer = input().lower()
2005-11-16 19:07:19 +00:00
return answer == 'y'
def exists(func,list):
2020-10-28 14:13:02 +00:00
return len(list(filter(func,list))) > 0
2005-11-16 19:07:19 +00:00
def forall(func,list):
2020-10-28 14:13:02 +00:00
return len(list(filter(func,list))) == len(list)
2005-11-16 19:07:19 +00:00
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