I'd use a list comprehension:
final = [[CP('id', ident), CP('name', name)] for (ident,name) in results]
But you mentioned map
, which you can also use:
final = map(lambda (ident,name): [CP('id',ident),CP('name',name)], results)
(Note that I didn't name the id variable id
because that conflicts with an existing global function in Python.)
In Python, comprehensions/generators are generally preferred over map
, because they're more general and arguably more legible. Admittedly, the relative lack of generality in map
is largely because Python's lambda
construct for creating anonymous functions is rather limited compared to what's available in more functional languages, where map
and friends reign supreme.