title: How to handle a pandas index independently of its number of levels?
body: <p>Is it possible to represent a Pandas index in a standardized form, regardless of its number of levels? The underlying problem is that <a href="https://pandas.pydata.org/docs/reference/api/pandas.Index.to_list.html" rel="nofollow noreferrer"><code>Index.to_list()</code></a> returns a flat list of objects, while <code>MultiIndex.to_list()</code> returns a list of tuples. How to overcome this inconsistency?</p>
  <p>My goal is to write functions that operate on indices independent of their number of levels. Currently, I need to standardize an input index, as illustrated below, which I think is a bit awkward.</p>
  <pre class="lang-py prettyprint-override"><code>def some_function(index):
      # Standardize input: represent index as list of tuples.
      # (This assumes that a multi-index has not been flattened yet.)
      if index.nlevels == 1:
          items = [(item,) for item in index]
      else:
          items = index.to_list()
      
      # ... 
  </code></pre>
  <p>I hoped that <a href="https://pandas.pydata.org/docs/reference/api/pandas.MultiIndex.to_flat_index.html" rel="nofollow noreferrer"><code>to_flat_index()</code></a> might solve my problem, but it doesn't.</p>