code: def make_csv(data):
      
      # Convert sub-dicts to news cols
      for entry in data:
          rval = entry
          if isinstance(data, dict):
              rval = data[entry]
          todel = []
          toadd = {}
          for key, val in rval.items():
              if isinstance(val, dict):
                  for key2, val2 in val.items():
                      toadd[str(key) + "[" + str(key2) + "]"] = val2
                  todel.append(key)
          for k in todel:
              del rval[k]
          for k, v in toadd.items():
              rval[k] = v
  
      # Convert everything to CSV
      columns = set()
      output = [[]]
      if isinstance(data, dict):
          output[0].append("id")
          for entry in data:
              for col in data[entry]:
                  columns.add(col)
      else:
          for entry in data:
              for col in entry:
                  columns.add(col)
  
      columns = sorted(columns)
  
      for col in columns:
          output[0].append(col)
  
      if isinstance(data, dict):
          for entry in data:
              new_output = [str(entry)]
              for col in columns:
                  new_output.append(str(data[entry][col]) if col in data[entry] else "")
              output.append(new_output)
      else:
          for entry in data:
              new_output = []
              for col in columns:
                  new_output.append(str(entry[col]) if col in entry else "")
              output.append(new_output)
  
      csv_string = io.StringIO()
      csv_writer = UnicodeWriter(csv_string)
      for row in output:
          csv_writer.writerow(row)
      csv_string.seek(0)
      web.header('Content-Type', 'text/csv; charset=utf-8')
      web.header('Content-disposition', 'attachment; filename=export.csv')
      return csv_string.read()
docs: Returns the content of a CSV file with the data of the dict/list data