def identity(what):
return what
def first(iterable, predicate=identity):
if iterable:
for x in iterable:
if predicate(x):
return x
return None
def to_string(ints):
return ','.join(str(i) for i in ints)
def to_ints(string):
""" Transform a string of comma-separated integers into a list of ints.
"""
ints = list()
for s in string.split(','):
try:
ints.append(int(s))
except ValueError:
pass
return ints