1

所以我有从这个函数创建的字典 x

    olist = ['a/b/c','a/b/c/d','b/c/d','x/y/z','a/b','d/e/f','i/j/k']

    def bulkFeed(objlist):
        x = {}
        for obj in objlist:
            #pdb.set_trace()
            dn_len = len(obj)
            if dn_len not in x:
                x[dn_len] = {}
            if obj not in x[dn_len]:
                x[dn_len][obj] = {}
            x[dn_len][obj].update({"commit":1,"ObjectRef":obj})
        return x

obj_dict = bulkFeed(olist)

 >>> obj_dict
    {3: {'a/b': {'commit': 1, 'ObjectRef': 'a/b'}}, 5: {'a/b/c': {'commit': 1, 'ObjectRef': 'a/b/c'}, 'd/e/f': {'commit': 1, 'ObjectRef': 'd/e/f'}, 'b/c/d': {'commit': 1, 'ObjectRef': 'b/c/d'}, 'x/y/z': {'commit': 1, 'ObjectRef': 'x/y/z'}, 'i/j/k': {'commit': 1, 'ObjectRef': 'i/j/k'}}, 7: {'a/b/c/d': {'commit': 1, 'ObjectRef': 'a/b/c/d'}}}

我想做的是像这样在 obj_dict

if 'a/b/c'.startswith('a/b'):
    update commit to 0 in 'a/b/c' level
if  'a/b/c/d'.startswith('a/b/c'):
    update commit to 0 in 'a/b/c/d' level

keep doing for every item in dictionary until reaching end of dict

感谢任何答案/提示将非常有帮助。'a/b/c' 源于内部字典级别,例如 'a/b/c/d' 词干

4

0 回答 0