title: Is there any smart way to combine overlapping paths in python?
body: <p>Let's say I have two path names: <strong>head</strong> and <strong>tail</strong>. They can overlap with any number of segments. If they don't I'd like to just join them normally. If they overlap, I'd like to detect the common part and combine them accordingly. To be more specific: If there are repetitions in names I'd like to find as long overlapping part as possible. Example</p>
  
  <pre><code>"/root/d1/d2/d1/d2" + "d2/d1/d2/file.txt" == "/root/d1/d2/d1/d2/file.txt"
  and not "/root/d1/d2/d1/d2/d1/d2/file.txt"
  </code></pre>
  
  <p>Is there any ready-to-use library function for such case, or I have to implement one?</p>