-
长风秋雁
这将获得所有ids和tool_ids拥有它们的人l = [(person['id'], person['tool']['tool_id']) for person in assignment if 'id' in person and 'tool' in person and 'tool_id' in person['tool']]for pair in l: print(*pair, sep=', ')印刷4734238, 383744734233, 38374
-
尚方宝剑之说
assignment = [{ 'id': "1001",'name': "kevin", 'tool': {'tool_id': '38374'}},{ 'id': "1002", 'name': "jeremy", 'tool': {'tool_id': '38378'}}]findThis = ['kevin', 'jeremy']for each in assignment: if each.get('name') in findThis: t = each.get('tool') print(each.get('id'), t.get('tool_id'))我希望它更容易理解。
-
慕桂英546537
这应该这样做:[[i.get('id'), i.get('tool').get('tool_id')] for i in assignment if i.get('name') in ['kevin','jeremy']]对于此示例,返回:[[4734238, '38374'], [4734233, '38374']]