File tree Expand file tree Collapse file tree 1 file changed +59
-1
lines changed
Expand file tree Collapse file tree 1 file changed +59
-1
lines changed Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ def tree():
2222 return defaultdict (tree )
2323
2424
25- if __name__ == '__main__' :
25+ def test_users () :
2626 users = tree ()
2727 users ['jack_1' ]['jack_2_1' ]['jack_3_1' ] = {}
2828 users ['jack_1' ]['jack_2_1' ]['jack_3_2' ] = {}
@@ -49,3 +49,61 @@ def tree():
4949
5050 # 第三层(users孙节点的key)
5151 print [i for i in users ['jack_1' ]['jack_2_1' ]]
52+
53+
54+ l = [
55+ {'u' : 4 , 'p' : 1 },
56+ {'u' : 10 , 'p' : 1 },
57+ {'u' : 5 , 'p' : 1 },
58+ {'u' : 6 , 'p' : 2 },
59+ {'u' : 7 , 'p' : 2 },
60+ {'u' : 8 , 'p' : 3 },
61+ {'u' : 9 , 'p' : 3 },
62+ {'u' : 11 , 'p' : 3 },
63+ {'u' : 12 , 'p' : 3 },
64+ {'u' : 13 , 'p' : 5 },
65+ {'u' : 14 , 'p' : 6 },
66+ {'u' : 15 , 'p' : 10 },
67+ {'u' : 17 , 'p' : 10 },
68+ {'u' : 19 , 'p' : 10 },
69+ {'u' : 20 , 'p' : 15 },
70+ {'u' : 21 , 'p' : 15 },
71+ {'u' : 22 , 'p' : 17 },
72+ {'u' : 23 , 'p' : 22 },
73+ ]
74+
75+
76+ def get_child_users (uid ):
77+ """
78+ 获取子节点
79+ :param uid:
80+ :return:
81+ """
82+ r = []
83+ for i in l :
84+ if i ['p' ] == uid :
85+ r .append (i ['u' ])
86+ return r
87+
88+
89+ def test_team (uid ):
90+ """
91+ 测试
92+ :return:
93+ """
94+ team = tree ()
95+ child_users = get_child_users (uid )
96+ for uid1 in child_users :
97+ team [uid1 ] = {}
98+ child_users2 = get_child_users (uid1 )
99+ for uid2 in child_users2 :
100+ team [uid1 ][uid2 ] = {}
101+ child_users3 = get_child_users (uid2 )
102+ for uid3 in child_users3 :
103+ team [uid1 ][uid2 ][uid3 ] = {}
104+ print json .dumps (team , indent = 4 )
105+
106+
107+ if __name__ == '__main__' :
108+ # test_users()
109+ test_team (1 )
You can’t perform that action at this time.
0 commit comments