original_docstring: Tabularize a list of dictionaries.
docstring: Tabularize a list of dictionaries.
docstring_tokens: Tabularize a list of dictionaries .
code: def tabularize(
      data: List[dict],
      keys: List[str] = None,
      gutter: str = ' ',
      join: bool = True
  ) -> Union[List[str], str]:
      '''Tabularize a list of dictionaries.'''
  
      # Load all keys if no explicit keys are provided
      if keys is None:
          keys = list(data[0].keys())
  
      # Calculate column widths for each key
      col_widths = {key: max(len(str(item[key])) for item in data) for key in keys}
  
      # Generate string outputs
      lines = []
      for item in data:
          s = gutter.join('{value:{width}}'.format(
              value=item[k],
              width=col_widths[k]
          ) for k in keys)
          lines.append(s)
  
      if join:
          return '\n'.join(lines)
  
      return lines
code_tokens: def tabularize ( data : List [ dict ] , keys : List [ str ] = None , gutter : str = ' ' , join : bool = True ) -> Union [ List [ str ] , str ] : if keys is None : keys = list ( data [ 0 ] . keys ( ) ) col_widths = { key : max ( len ( str ( item [ key ] ) ) for item in data ) for key in keys } lines = [ ] for item in data : s = gutter . join ( '{value:{width}}' . format ( value = item [ k ] , width = col_widths [ k ] ) for k in keys ) lines . append ( s ) if join : return '\n' . join ( lines ) return lines
short_docstring: Tabularize a list of dictionaries.
short_docstring_tokens: Tabularize a list of dictionaries .
comment: '''Tabularize a list of dictionaries.'''$SEP$# Load all keys if no explicit keys are provided$SEP$# Calculate column widths for each key$SEP$# Generate string outputs