def as_tuples_iter(vqs, cols): """[{a=1, b=2}, {a=3, b=4}], ('a', 'b') -> (a=1, b=2), (a=3, b=4), ...""" Row = namedtuple('Row', cols) for row in vqs: yield Row(*[row[key] for key in cols])
def as_tuples_iter(vqs, cols): """ Useful after queryset.values() """ Row = namedtuple('Row', cols) for row in vqs: yield Row(*[row[key] for key in cols])
def as_tuples(vqs, cols): """[{a=1, b=2}, {a=3, b=4}], ('a', 'b') -> [(a=1, b=2), (a=3, b=4)]""" Row = namedtuple('Row', cols) return [Row(*[row[key] for key in cols]) for row in vqs]
def as_tuples(vqs, cols): """ Useful after queryset.values() """ Row = namedtuple('Row', cols) return [Row(*[row[key] for key in cols]) for row in vqs]