Skip to content

Instantly share code, notes, and snippets.

@inky
Created April 3, 2009 18:41
Show Gist options
  • Save inky/89890 to your computer and use it in GitHub Desktop.
Save inky/89890 to your computer and use it in GitHub Desktop.
def map_results(fields, rows):
keys = [f.split('.')[-1] for f in fields]
return tuple(dict(zip(keys, row)) for row in rows)
# >>> fields = ('x.id', 'y.name', 'spork')
# >>> rows = [(1, 2, 3), (4, 5, 6)]
# >>> for row in map_results(fields, rows):
# ... print row
# ...
# {'id': 1, 'name': 2, 'spork': 3}
# {'id': 4, 'name': 5, 'spork': 6}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment