def group(cls, expr):
def group_action(s, l, t):
try:
lst = t[0].asList()
except (IndexError, AttributeError):
lst = t
return [cls(lst)]
return Group(expr).setParseAction(group_action)