ocean #4459(2007/11/28 08:24 GMT) [ Python ] Rating4/4=1.00
クロージャで実装してみました。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
def create(path_list): root = {} for path in path_list: node = root for name in path.rstrip("/").split("/"): node = node.setdefault(name, {}) def ls(path): node = root for name in path.rstrip("/").split("/"): node = node.get(name, None) if node is None: return [] return [name + "/" if children else name \ for name, children in node.iteritems()] return ls ls = create(["aaa/bbb","aaa/ccc","aaa/ddd/eee","bbb/ddd/eee"]) print ls("aaa/") print ls("aaa/ddd/")
Rating4/4=1.00-0+
[ reply ]
ocean
#4459()
[
Python
]
Rating4/4=1.00
クロージャで実装してみました。
Rating4/4=1.00-0+
[ reply ]