rintrix/utils.py

9 lines
319 B
Python
Raw Normal View History

2022-02-24 16:27:55 +11:00
def get_or_create(needle,haystack,default):
"""
This is a wrapper for filter that can add stuff. Nothing special. Needle is a function, default isn't. Haystack is a list. I might fix that later.
"""
f=filter(needle,haystack)
try: return next(f)
except StopIteration: pass
haystack.append(default)
return default