def format_dictlist(dictlist, features):
 def dict_to_entry(dct):
  ' Convert dictionary to a list for a csv row '
  relevant_items = [(k, v) for (k, v) in dct.items() if (k in features)]
  ordered = sorted(relevant_items, key=(lambda (k, v): header.index(k)))
  vals = [v for (_, v) in ordered]
  return vals
 header = features
 datarows = map(dict_to_entry, dictlist)
 return (header, datarows)

def format_dictlist ( dictlist , features ) : def dict_to_entry ( dct ) : relevant_items = [ ( k , v ) for ( k , v ) in dct . items ( ) if ( k in features ) ] ordered = sorted ( relevant_items , key = ( lambda ( k , v ) : header . index ( k ) ) ) vals = [ v for ( _ , v ) in ordered ] return vals header = features datarows = map ( dict_to_entry , dictlist ) return ( header , datarows )
convert a list of dictionaries to be compatible with create_csv_response dictlist is a list of dictionaries all dictionaries should have keys from features features is a list of features example code: dictlist = [ label1: value-1 .