Python Forum
How to append to a dictionary?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to append to a dictionary?
#2
I solved this issue!
Here's what ended up working for me...

    response=requests.get(url + id, headers=h, params=p).json()
    inbound_dict = {}
    for item in response['messages']:
        conv_id = item['conversationId']
        if conv_id not in inbound_dict:
            inbound_dict[conv_id]={item['id'] : {'msg_id' : item['id'], 'body' : item['body']}}
        else:
            inbound_dict[conv_id][item['id']] = {'msg_id' : item['id'], 'body' : item['body']}
    pprint(inbound_dict)
Reply


Messages In This Thread
How to append to a dictionary? - by t4keheart - Feb-04-2020, 09:50 PM
RE: How to append to a dictionary? - by t4keheart - Feb-05-2020, 04:25 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Cant Append a word in a line to a list err "str obj has no attribute append Sutsro 2 2,656 Apr-22-2020, 01:01 PM
Last Post: deanhystad
  Iterate through a list of dictionary and append a new value. erina 1 2,134 May-16-2019, 09:55 AM
Last Post: perfringo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020