Commit 87552cb3 authored by Michael Büsch's avatar Michael Büsch

common/util: Add getany()

Signed-off-by: Michael Büsch's avatarMichael Buesch <>
parent 7e760ea9
......@@ -257,6 +257,18 @@ def isiterable(obj):
return False
def getany(iterable, exception=KeyError):
"""Get an arbitrary item from an iterable.
If the iterable is empty, exception is raised.
If exception is None, None is returned instead.
return next(iter(iterable))
except StopIteration:
if exception:
raise exception
return None
def toList(value):
"""Returns value, if value is a list.
Returns a list with the elements of value, if value is a set.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment