Let's say I have a series of incompletely qualified paths, which are missing some parts, but are guaranteed to have two properties:
- The final part of both the incompletely and the fully qualified paths will be exactly equal, and
- The order of each part of the incompletely qualified path will match the actual order of the parts of the fully qualified path.
For example,
p1 = '/foo/baz/myfile.txt'
p2 = '/bar/foo/myfile.txt'
actual = '/foo/bar/baz/myfile.txt'
In this case, p1
will match, but p2
will not, because in the actual path, bar
occurs after foo
. Easy enough: [actual.split('/').index(part) for part in p1.split('/')]
will be an ordered list, but the same comprehension but for p2
will not.
But what happens if there are repetitions in the path?
p1 = '/foo/bar/bar/myfile.txt'
p2 = '/bar/bar/baz/myfile.txt'
actual = '/foo/bar/baz/bar/myfile.txt'
How can I identify that p1
does match, but p2
does not (because, although baz
occurs after the first bar
, it does not occur after the second?