names = []
contacts = resp['data']['user']['contact_list']
for contact in contacts:
contact_name = contact['name']
friends_names = [x['name'] for x in contact['friends']]
names.append(contact_name)
names.extend(friends_names)
data = {
'user': [
{'name': 'Alex', 'age': 18},
{ 'name': 'Jack', 'age': 23},
{'name': 'Anna', 'age': 17}
]
}
# Способ 1
names = []
for user in data['user']:
names.append(user['name'])
print(names)
# Способ 2
names = [user['name'] for user in data['user']]
print(names)
# Способ 3
names = list(map(lambda x: x['name'], data['user']))
print(names)
# Выбирайте, какой вам больше по душе