datatracker/ietf/utils/listop.py
2007-06-05 15:05:31 +00:00

19 lines
466 B
Python

import operator
def orl(list):
""" Return the "or" of every element in a list.
Used to generate "or" queries with a list of Q objects. """
if list:
return reduce(operator.__or__, list)
else:
return None
def flattenl(list):
""" Flatten a list one level, e.g., turn
[ ['a'], ['b'], ['c', 'd'] ] into
[ 'a', 'b', 'c', 'd' ]
"""
if list:
return reduce(operator.__concat__, list)
else:
return []