Skip to content

Consider adding a zipdict() function #291

Open
@ankostis

Description

@ankostis

Please consider adding a zipdict() function that mimics the zip() function but on dictionaries This utility allows to iterate the items (key,value) of a list of dictionaries based on their common keys.

The necessity for such a function is described in this SO question: http://stackoverflow.com/questions/16458340/python-equivalent-of-zip-for-dictionaries

A starting implementation would be based on @Volatilty's suggestion in the above question:

def zipdict(*dcts):
    if dcts:
        for k in set(dcts[0]).intersection(*dcts[1:]):
            yield k, tuple(d[k] for d in dcts)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions