List of paths

Scott David Daniels Scott.Daniels at Acm.Org
Thu Apr 2 00:29:05 CEST 2009

Nico Grubert wrote:
> Dear Python developers... I have the following (sorted) list....
> I want to remove all paths x from the list if there is a path y in the 
> list which is part of x so y.startswith(x) is true.
> The list I want to have is:
> ['/notebook', '/desktop', '/server/hp/proliant']
> Any idea how I can do this in Python?
> Thanks in advance
> Nico
Here's a tricky case that doesn't show up in your example:
In each case above, the directory names are distinct.
how about:
['/desk', '/desk/ethanallen', '/desk/ikea',
  '/desktop', /desktop/pc', '/desktop/mac']
Should the answer be ['/desk'] or ['/desk', '/desktop'] ?

--Scott David Daniels
Scott.Daniels at Acm.Org

More information about the Python-list mailing list