Parsing multiple of common value in Dict Python (usernames)

I have a dict that's retrieved from an API that lists profiles as such:

    {
        'sections':  None,
         'global_blacklist_sample':  None,
         'users':  [
            {
                'pk':  20172538534,
                 'username':  'username1',
                 'full_name':  'name1',
                 'is_private':  True,
                 'profile_pic_url':  'https: //instagram.fsin5-1.fna.fbcdn.net/v/t51.2885-19/s150x150/73546075_539443043502574_2665415317592735744_n.jpg?_nc_ht=instagram.fsin5-1.fna.fbcdn.net&_nc_ohc=ZK6_BMRPA68AX8uf94G&_nc_tp=25&oh=cdaaf6f4d67261ec05c5db86efd55b12&oe=5FE02ABB',
                 'profile_pic_id':  '2182146027925079168_20172038574',
                 'is_verified':  False,
                 'has_anonymous_profile_picture':  False,
                 'reel_auto_archive':  'on',
                 'allowed_commenter_type':  'any',
                 'account_badges':  [
                    
                ],
                 'latest_reel_media':  0,
                 'story_reel_media_ids':  [
                    
                ]
            },
             {
                'pk':  13046517457,
                 'username':  'username2',
                 'full_name':  'name2',
                 'is_private':  True,
                 'profile_pic_url':  'https: //instagram.fsin5-1.fna.fbcdn.net/v/t51.2885-19/s150x150/92018644_888563998275610_476140774514229248_n.jpg?_nc_ht=instagram.fsin5-1.fna.fbcdn.net&_nc_ohc=nL8P8zD9MR8AX9aoaLB&_nc_tp=25&oh=c46c751ed4e52e62775c446a3f29e5f9&oe=5FE0276C',
                 'profile_pic_id':  '2281189669318307392_13046517447',
                 'is_verified':  False,
                 'has_anonymous_profile_picture':  False,
                 'account_badges':  [
                    
                ],
                 'latest_reel_media':  0,
                 'story_reel_media_ids':  [
                    
                ]
            },
             {
                'pk':  8373043335,
                 'username':  'username3',
                 'full_name':  'name3',
                 'is_private':  True,
                 'profile_pic_url':  'https: //instagram.fsin5-1.fna.fbcdn.net/v/t51.2885-19/s150x150/110630893_306355594052903_5751168818852707872_n.jpg?_nc_ht=instagram.fsin5-1.fna.fbcdn.net&_nc_ohc=SrVfiL5_r9cAX8yTCCv&_nc_tp=25&oh=68db435ac44869d772c16aed8cbdaeb1&oe=5FDDE888',
                 'profile_pic_id':  '2358844203752433124_8373061335',
                 'is_verified':  False,
                 'has_anonymous_profile_picture':  False,
                 'account_badges':  [
                    
                ],
                 'latest_reel_media':  1605694021,
                 'story_reel_media_ids':  [
                    
                ]
            }
        ],
         'big_list':  False,
         'next_max_id':  None,
         'page_size':  200,
         'status':  'ok'
    }

I'd like for it to output/print all the usernames along with the is_private value. So for eg: "username1:True". There's many profiles in the actual dict, so manually using as such wont work.

    print(dict["users"][0]["username"])
    print(dict["users"][1]["username"])
    print(dict["users"][2]["username"])

This code snippet works, but only if i remove the things below the code snippet

def iterateDictionary2(key_name, key_name2, some_list):
    for d in some_list:
        print(d[key_name] + ":" + str(d[key_name2]))

iterateDictionary2('username', 'is_private', fllwrs)
    {
        'sections':  None,
         'global_blacklist_sample':  None,
         'users':  
and
,
         'big_list':  False,
         'next_max_id':  None,
         'page_size':  200,
         'status':  'ok'
    }

Would appreciate any help, thank you!



Read more here: https://stackoverflow.com/questions/64897825/parsing-multiple-of-common-value-in-dict-python-usernames

Content Attribution

This content was originally published by sezaira at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: