title: Python: How to get last n elements of a file path
body: <p>Suppose I have a path like this:</p>
  <pre><code>/folderA/folderB/folderC/item1
  /folderA/folderB/folderX/item2
  /folderA/folderB/folderF/item1
  /folderA/folderB/folderQ/item5
  </code></pre>
  <p>How do I get the last two elements of the file path?</p>
  <pre><code>folderC/item1
  folderX/item2
  folderF/item1
  folderQ/item5
  </code></pre>
  <p>I know I can git either the directory or the file by</p>
  <pre><code>&gt;&gt;&gt; os.path.basename('/folderA/folderB/folderC/item1')
  &gt;&gt;&gt; item1
  
  
  &gt;&gt;&gt; os.path.dirname('/folderA/folderB/folderC/item1')
  &gt;&gt;&gt; /folderA/folderB/folderC/
  </code></pre>