Add tags

Add tags to the following comment

クロージャで実装してみました。

 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/")

Add tags

The input will be splited to tags with space.

Index

Feed

Other

Link

Pathtraq

loading...