code: def extract_fields(d, fields, delimiter='|'):
      
      rd = {}
      for f in fields:
          v = d.get(f, None)
          if isinstance(v, (str, unicode)):
              v = v.encode('utf8')
          elif isinstance(v, list):
              v = delimiter.join(v)
          rd[f] = v
      return rd
docs: get values out of an object ``d`` for saving to a csv