Re: List of paths

2009-04-08 Thread Nico Grubert
> 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'] ? Hi Scott good po

Re: List of paths

2009-04-01 Thread Scott David Daniels
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 ide

Re: List of paths

2009-04-01 Thread Paul McGuire
On Apr 1, 3:57 am, Nico Grubert wrote: > Dear Python developers > > I have the following (sorted) list. > ['/notebook', >   '/notebook/mac', >   '/notebook/mac/macbook', >   '/notebook/mac/macbookpro', >   '/notebook/pc', >   '/notebook/pc/lenovo', >   '/notebook/pc/hp', >   '/notebook/pc/sony', >

Re: List of paths

2009-04-01 Thread Eugene Perederey
Sure, generators rock! :-) 2009/4/1 andrew cooke : > Nico Grubert wrote: >>> May be not so much pythonic, but works >>> >>> for i in range(len(q)): >>>     for x in q[i:]: >>>        if x.startswith(q[i]) and x!=q[i]: >>>            q.remove(x) >> >> ...but works fine. Thanks, Eugene. >> Also th

Re: List of paths

2009-04-01 Thread andrew cooke
Nico Grubert wrote: >> May be not so much pythonic, but works >> >> for i in range(len(q)): >> for x in q[i:]: >>if x.startswith(q[i]) and x!=q[i]: >>q.remove(x) > > ...but works fine. Thanks, Eugene. > Also thanks to Andrew. Your example works fine, too. Thanks to remind me

Re: List of paths

2009-04-01 Thread Nico Grubert
May be not so much pythonic, but works for i in range(len(q)): for x in q[i:]: if x.startswith(q[i]) and x!=q[i]: q.remove(x) ...but works fine. Thanks, Eugene. Also thanks to Andrew. Your example works fine, too. Thanks to remind me of the 'yield' statement! ;-) Regard

Re: List of paths

2009-04-01 Thread dorzey
You could use the followingm, where the_list is your list. (I'm new to python so there might be a better way): toremove = [] for x in the_list: for y in the_list: if y.startswith(x) and y != x: toremove.append(y) difference = filter(lambda x:x not

Re: List of paths

2009-04-01 Thread andrew cooke
>>> def filter(values): ... last = None ... for value in values: ... if last is None or not value.startswith(last): ... yield value ... last = value ... >>> for x in filter(['/notebook', ]): ... print(x) ... /notebook /desktop /server/hp/proliant andrew Nico Grubert wr