A
A
Artem Marsh2018-11-10 20:42:01
Python
Artem Marsh, 2018-11-10 20:42:01

How to sort first and last name in VK API?

(I write in python)
Let's say I wanted to see the list of my friends in VK, but that's bad luck:
I write not only the names and surnames of friends, but also extra garbage!

print(vk.friends.get(fields='first_name, last_name'))

and the following is displayed:
{'count': xxxxxx, 'items': [{'id': xxxxxxxx, 'first_name': 'lol', 'last_name': 'ololoev
' extra signs, attributes, etc.
For example
lol ololoev - idxxxxxx
Don't throw slippers, Newbie)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
danyadev, 2018-11-11
@danyadev

write this code:

user = vk.friends.get(fields='first_name,last_name')['items'][0]
print('id{0} - {1} {2}'.format(user['id'], user['first_name'], user['last_name']))

H
Helow19274, 2018-11-10
@Helow19274

https://pythonworld.ru/osnovy/formatirovanie-strok...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question