#StackBounty: #python #logging How to add log info in the Code in python in the loop

Bounty: 50

  • Below is the dictionary
  • There are two ids, I need to generat
  • Once extract of completion of first id i need to get an info saying First id(100) is completed
  • Once extract of completion of second id i need to get an info saying second id(101) is completed

logger.info('extraction id' + str(id) + 'completed')

logger.info('extraction id' + + str(id) + 'completed')

Expected out

    test = [{"id":"100","name":"A",
    "policies":[{"id":"332","name":"Second division","parent":"Marketing"},
    {"id":"3323","name":"First division","parent":"Marketing"}]},
    "policies":[{"id":"332","name":"Second division","parent":"Marketing"},
    {"id":"3323","name":"First division","parent":"Marketing"}]}]


def do_the_thing(lst):
    resp = []

    parents_mapper = {
        'Marketing': 'level1',
        'Advertising': 'level2'

    for el in lst:
        d = {
            'id': el['id'],
            'name': el['name'],
            'Business': [],
            'level1': [],
            'level2': []
        for business in el.get('Business', []):
            business_name = business.get('name')
            if business_name:

        for policy in el.get('policies', []):
            policy_parent = policy.get('parent')
            parent_found = parents_mapper.get(policy_parent)
            policy_name = policy.get('name')
            if parent_found and policy_name:

    return resp

#def lambda_handler(event,context):
if __name__ == '__main__':
    import pprint
    pp = pprint.PrettyPrinter(4)

output for 2 ids

    "id": "100",
    "name": "A",
    "Business": ["Enterprise", "Customer"],
    "level1": ['Second division', 'First division'],
    "level2": [None ]
    "id": "101",
    "name": "B",
    "Business": ["Enterprise", "Customer"],
    "level1": ['Second division', 'First division'],
    "level2": [None ]

First id completed then i will get extraction id' 100 is completed' second id completed then i will get extraction id' 10 is completed’`

** Expected out_one

extraction id' 100 is completed'
extraction id' 101 is completed'

** Expected out_two

extraction Business' 100 is completed'
extraction policy' 100 is completed'
extraction level1' 100 is completed'
extraction Business' 101 is completed'
extraction policy' 101 is completed'
extraction level1' 101 is completed'

Get this bounty!!!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.