def nodesets2affiliations(communities):
    """
    Transform community format to "snapshot_affiliations"

    Representation expected in input: dictionary, key= community ID, value= node set
    Representation in output: dictionary, key=node, value=set of snapshot_affiliations ID

    :param communities: dictionary, key=node set, value= community ID
    :return: dictionary, key=node, value=list of snapshot_affiliations ID
    """
    node2com = dict()
    for id, nodes in communities.items():
        for n in nodes:
            node2com.setdefault(n,set())
            node2com[n].add(id)
    return node2com