<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def group_by(self, fields, items=None):
 """ Returns a dict of lists of items, grouped by the given fields. ``fields`` can be a string (one field) or an iterable of field names. """

        result = defaultdict(list)
        if items is None:
            items = self.items()

        try:
            key = operator.attrgetter(fields + '')
        except TypeError:
            def key(obj, names=tuple(fields)):
                'Helper to return group key tuple'
                return tuple(getattr(obj, x) for x in names)

        for item in items:
            result[key(item)].append(item)

        return result