Organizing dynamic list listings

Sorry if this was answered (I searched and found nothing). Let me know and I will remove it immediately.

I am writing a program that calls an API call that returns multiple lists of different lengths depending on the call (e.g. facebook API call). Enter the name of the person, and the list of images is returned, and in each picture there is a list that "loved" each photo. I want to save the list from the list of "likes").

#Import urllib for API request
import urllib.request
import urllib.parse
#First I have a function that takes two arguments, first and last name
#Function will return a list of all photos the person has been tagged in facebook
def id_list_generator(first,last):
    #Please note I don't actually know facebook API, this part wil not be reproducible
    pic_id_request = urllib.request.open('www.facebook.com/pics/id/term={first}+{last}[person]')
    pic_id_list = pic_id_request.read()
    for i in pic_id_list:
       id_list.append(i)
  return(id_list)
#Now, for each ID of a picture, I will generate a list of people who "liked" that picture.
#This is where I have trouble.  I don't know how to store these list of lists.
for i in id_list:
    pic_list = urllib.request.open('www.facebook.com/pics/id/like/term={i}[likes]')
    print pic_list

This will print multiple love lists for each image that the person has been tagged in:

foo, bar
bar, baz
baz, foo, qux
norf

I really don't know how to store them honestly.

I thought of using a list that would look like this after adding:

foo = [["foo", "bar"], ["bar","baz"],["baz","foo","qux"],["norf"]]

, . , , . , , .

+4
2

, :

:

facebook_likes = [{
    "first_name": "John",
    "last_name": "Smith",
    "image_link": "link",
    "likes": ["foo"]
}, {
    "first_name": "John",
    "last_name": "Doe",
    "image_link": "link",
    "likes": ["foo", "bar"]
}]

for like in facebook_likes:
    print like
    print like["likes"]
    print like["likes"][0]

JSON. , API. , Python JSON .

+2

, Python 2D-. . : Python sort()

0

Source: https://habr.com/ru/post/1622845/


All Articles