<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_key(dirnames, key):
 """Group a set of output directories according to a model parameter. Parameters dirnames: list[str] Output directories key: various A field of a :class:`Model` instance. Returns ------- groups: dict[various: list[str]] For each value of `key` that is found at least once in the models, a list of the output directories where `key` is that value. """

    groups = defaultdict(lambda: [])
    for dirname in dirnames:
        m = get_recent_model(dirname)
        groups[m.__dict__[key]].append(dirname)
    return dict(groups)