code: def _flatten_list(x, include_tuple=False):
      """Flatten an arbitrarily nested list into a new list.
  
      This can be useful to select pandas DataFrame columns.
  
      From https://stackoverflow.com/a/16176969/10581531
  
      Examples
      --------
      >>> from pingouin.utils import _flatten_list
      >>> x = ['X1', ['M1', 'M2'], 'Y1', ['Y2']]
      >>> _flatten_list(x)
      ['X1', 'M1', 'M2', 'Y1', 'Y2']
  
      >>> x = ['Xaa', 'Xbb', 'Xcc']
      >>> _flatten_list(x)
      ['Xaa', 'Xbb', 'Xcc']
  
      >>> x = ['Xaa', ('Xbb', 'Xcc'), (1, 2), (1)]
      >>> _flatten_list(x)
      ['Xaa', ('Xbb', 'Xcc'), (1, 2), 1]
  
      >>> _flatten_list(x, include_tuple=True)
      ['Xaa', 'Xbb', 'Xcc', 1, 2, 1]
      """
      # If x is not iterable, return x
      if not isinstance(x, collections.abc.Iterable):
          return x
      # Initialize empty output variable
      result = []
      # Loop over items in x
      for el in x:
          # Check if element is iterable
          el_is_iter = isinstance(el, collections.abc.Iterable)
          if el_is_iter:
              if not isinstance(el, (str, tuple)):
                  result.extend(_flatten_list(el))
              else:
                  if isinstance(el, tuple) and include_tuple:
                      result.extend(_flatten_list(el))
                  else:
                      result.append(el)
          else:
              result.append(el)
      # Remove None from output
      result = [r for r in result if r is not None]
      return result
  
file_path: pingouin/pingouin/utils.py
imports: import numbers
  import numpy
  import pandas
  import itertools
  import collections.abc
  from tabulate import tabulate
  from .config import options
label_desc: Use image node_id 7 for calling a global function with example usage: _flatten_list(x, include_tuple) and returns: result, x