Python Forum
How to access specific values from a dict?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to access specific values from a dict?
#4
The way you have it is JSON format without any assignment. If you assign it to a variable you you can use it as a dictionary. Everything there is under the first key 1005672, so you would do this to get the sub key of 5366005 print(d[1005672][5366005])
d = {1005672: {4461048: {'body': 'Mnow test test', 'msg_id': 4461048},
           4620511: {'body': 'test sms,test sms', 'msg_id': 4620511},
           4620584: {'body': 'test sms', 'msg_id': 4620584},
           4646648: {'body': 'test sms', 'msg_id': 4646648},
           4646877: {'body': 'test sms', 'msg_id': 4646877},
           4671891: {'body': 'test sms', 'msg_id': 4671891},
           4697824: {'body': 'test sms', 'msg_id': 4697824},
           4700841: {'body': 'test sms', 'msg_id': 4700841},
           5149461: {'body': 'Is it?', 'msg_id': 5149461},
           5159744: {'body': 'end of day test', 'msg_id': 5159744},
           5159829: {'body': 'trying again and again', 'msg_id': 5159829},
           5327356: {'body': 'test for convo id', 'msg_id': 5327356},
           5327606: {'body': 'eventually this will work!', 'msg_id': 5327606},
           5327619: {'body': 'this will work i say!', 'msg_id': 5327619},
           5327736: {'body': 'testing again\r\n', 'msg_id': 5327736},
           5332767: {'body': 'testing testing 1..2...3...', 'msg_id': 5332767},
           5333204: {'body': 'testing the convID part...', 'msg_id': 5333204},
           5333257: {'body': 'take 2!', 'msg_id': 5333257},
           5333489: {'body': 'aaaaaaaaaaaand ACTION!', 'msg_id': 5333489},
           5337141: {'body': 'does it work?', 'msg_id': 5337141},
           5363443: {'body': 'Test', 'msg_id': 5363443},
           5365638: {'body': 'testing again', 'msg_id': 5365638},
           5366005: {'body': 'testing sms ID', 'msg_id': 5366005}}}

print(d[1005672][5366005])
Recommended Tutorials:
Reply


Messages In This Thread
RE: How to access specific values from a dict? - by metulburr - Feb-05-2020, 06:50 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to access values returned from inquirer cspower 6 1,147 Dec-26-2023, 09:34 PM
Last Post: cspower
  Printing specific values out from a dictionary mcoliver88 6 1,639 Apr-12-2023, 08:10 PM
Last Post: deanhystad
  Creating a numpy array from specific values of a spreadsheet column JulianZ 0 1,281 Apr-19-2022, 07:36 AM
Last Post: JulianZ
  dict class override: how access parent values? Andrey 1 1,772 Mar-06-2022, 10:49 PM
Last Post: deanhystad
  Sum the values in a pandas pivot table specific columns klllmmm 1 4,876 Nov-19-2021, 04:43 PM
Last Post: klllmmm
  Removing nan values from a dict tomtom 8 7,650 Oct-05-2021, 06:44 PM
Last Post: tomtom
  Annotating plot bar from values of other a specific column celinafregoso99 0 2,068 Mar-10-2021, 03:19 PM
Last Post: celinafregoso99
  Trouble with converting list , dict to int values! faryad13 7 4,002 Sep-04-2020, 06:25 AM
Last Post: faryad13
  Check for specific values on screen and2handles 2 2,502 Jun-17-2020, 05:24 AM
Last Post: and2handles
  access dictionary with keys from another and write values to list redminote4dd 6 3,487 Jun-03-2020, 05:20 PM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

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