title: How to move up n directories in Pythonic way?
body: <p>I'm looking for a pythonic way to move up <code>n</code> directories from a given directory.</p>
  
  <p>Let's say we have the example path <code>/data/python_env/lib/python3.6/site-packages/matplotlib/mpl-data</code>. If we were to move up <code>n=2</code> directories we should end up at <code>/data/python_env/lib/python3.6/site-packages</code>.</p>
  
  <p>The following works to move up <code>n</code> directories:</p>
  
  <pre><code>up_n = lambda path, n: '/'.join(path.split('/')[:-n])
  </code></pre>
  
  <p>However, it's not very readable and fails for paths on windows machines. In essence, it doesn't feel a very pythonic solution.</p>
  
  <p>Is there a better, more pythonic solution, maybe using the <code>os</code> module?</p>