def flatten_reply(reply): """Flatten node replies. Convert from a list of replies in this format:: [{'*****@*****.**': reply}, {'*****@*****.**': reply}] into this format:: {'*****@*****.**': reply, '*****@*****.**': reply} """ nodes, dupes = {}, set() for item in reply: [dupes.add(name) for name in item if name in nodes] nodes.update(item) if dupes: warnings.warn( DuplicateNodenameWarning( W_DUPNODE.format( pluralize(len(dupes), 'name'), ', '.join(sorted(dupes)), ), )) return nodes
def flatten_reply(reply): nodes = {} seen = set() for item in reply: dup = next((nodename in seen for nodename in item), None) if dup: warnings.warn(DuplicateNodenameWarning(W_DUPNODE.format(dup), )) seen.update(item) nodes.update(item) return nodes
def flatten_reply(reply): nodes, dupes = {}, set() for item in reply: [dupes.add(name) for name in item if name in nodes] nodes.update(item) if dupes: warnings.warn(DuplicateNodenameWarning( W_DUPNODE.format( pluralize(len(dupes), 'name'), ', '.join(sorted(dupes)), ), )) return nodes