- 论坛徽章:
- 0
|
本帖最后由 liaozd 于 2014-01-10 17:25 编辑
回复 10# ssfjhh
想法真的很好,很受启发,谢谢。
但是如果是这样['/home', '/home/tmp1/tmp2/']就不行了,我改进了一下- dirs = ['/var/log', '/var/lib', '/library', '/home/tmp1/tmp2/tmp3/tmp3','/home/tmp1/tmp2/tmp3/tmp3/tmp4'
- '/homeland', '/home/tmp1', '/home/tmp1/tmp2', '/home']
- uniq = []
- for path in dirs:
- i = path
- while i is not '':
- i = i.rpartition('/')[0]
- if i in dirs:
- flag = False
- break
- else:
- flag = True
- if flag is True:
- uniq.append(path)
- print uniq
- 输出:['/home', '/library', '/var/lib', '/var/log']
复制代码 |
|