import collections


def _group_by_id(objs):
    """Return a dictionary whose keys are MBIDs and whose values are
    lists of objects (Albums or Items) with that ID.
    """
    counts = collections.defaultdict(list)
    for obj in objs:
        mbid = getattr(obj, 'mb_trackid', obj.mb_albumid)
        counts[mbid].append(obj)
    return counts