Stack Exchange
Combine strings (paths) without duplication of parts
I have two paths:
a = '/folder1/subfolder/'
b = '/subfolder/folder2'

How to combine them into 
c = '/folder1/subfolder/folder2/'

in the simplest way?

Checking only the last component of a, you could do:
A = a.strip('/').split('/')
B = b.strip('/').split('/')
if A[-1] == B[0]:
    print("/{}/".format("/".join(A + B[1:])))


Should use os.path.sep over /
