how do i make a nested dictionary in python?

jaychandra

I'm trying to make an API that fetches memes from Reddit and I am stuck at creating JSON data with nested dictionaries. I have the following dictionaries and I want to merge them together. How do I go about it?

{
  "author": "Mizanur1214",
  "nsfw": false,
  "subreddit": "dankmemes",
  "title": "They do be like that",
  "upvotes": 33302,
  "url": "https://i.imgur.com/xZpJFQU.jpg"
}

and the other one as follows

{
  "author": "Kristis1",
  "nsfw": false,
  "subreddit": "me_irl",
  "title": "me irl",
  "upvotes": 1941,
  "url": "https://i.redd.it/u2qesppixhh61.jpg"
}

I want to make something like the following in python

{
{
  "author": "Mizanur1214",
  "nsfw": false,
  "subreddit": "dankmemes",
  "title": "They do be like that",
  "upvotes": 33302,
  "url": "https://i.imgur.com/xZpJFQU.jpg"
},
{
  "author": "Kristis1",
  "nsfw": false,
  "subreddit": "me_irl",
  "title": "me irl",
  "upvotes": 1941,
  "url": "https://i.redd.it/u2qesppixhh61.jpg"
}
}
Krishna Chaurasia

As others pointed out the result is not a valid json or dict.

You need a key for the dict object:

a = {
  "author": "Mizanur1214",
  "nsfw": false,
  "subreddit": "dankmemes",
  "title": "They do be like that",
  "upvotes": 33302,
  "url": "https://i.imgur.com/xZpJFQU.jpg"
}

b = {
  "author": "Kristis1",
  "nsfw": false,
  "subreddit": "me_irl",
  "title": "me irl",
  "upvotes": 1941,
  "url": "https://i.redd.it/u2qesppixhh61.jpg"
}

res = {"items": [a, b]}

print(res)

Output:

{'items': [{'author': 'Mizanur1214', 'nsfw': None, 'subreddit': 'dankmemes', 'title': 'They do be like that', 'upvotes': 33302, 'url': 'https://i.imgur.com/xZpJFQU.jpg'}, {'author': 'Kristis1', 'nsfw': None, 'subreddit': 'me_irl', 'title': 'me irl', 'upvotes': 1941, 'url': 'https://i.redd.it/u2qesppixhh61.jpg'}]}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How do I make a dictionary from a Python counter with the right keys?

From Dev

How do i extract from a nested dictionary?

From Dev

How do I represent dictionary of dictionary in Python

From Dev

How do I print everything from a dictionary nested in a dictionary

From Dev

How do I make a dictionary of events?

From Dev

How do I make ngFor for dictionary in Angular?

From Dev

How do I make ngFor for dictionary in Angular?

From Dev

How do i make a nested match in regex?

From Dev

I have nested lists as entries to a Python dictionary. How do I print the nested list whose first elements is "S"?

From Dev

I have nested lists as entries to a Python dictionary. How do I print the nested list whose first elements is "S"?

From Dev

How do I work with a nested dictionary's name?

From Dev

How do I append an element to an array in a nested dictionary

From Dev

How do you create a dictionary from nested lists in Python?

From Dev

how to sort nested dictionary python?

From Dev

How to create nested dictionary in python

From Dev

How do I make this nested for loop work faster

From Dev

How do I make a new array nested sorted maps?

From Dev

How to make a nested dictionary , IOS - Objective C

From Dev

How do I loop through a nested context dictionary in Django when I have no idea the structure I will recieve

From Dev

How do I make a dictionary with integers as keys out of dictionary with tuples as keys

From Dev

How do you make this shape in Python with nested loops?

From Dev

How do I make a python script executable?

From Dev

Numerical Python - how do I make this a ufunc?

From Dev

How do I make an object mutable in python?

From Dev

How do I make a float in Python?

From Dev

How do i make a game director in python?

From Dev

How do I make a grid in python?

From Dev

How do I make this python app installable?

From Dev

How do I make a timer in python?

Related Related

  1. 1

    How do I make a dictionary from a Python counter with the right keys?

  2. 2

    How do i extract from a nested dictionary?

  3. 3

    How do I represent dictionary of dictionary in Python

  4. 4

    How do I print everything from a dictionary nested in a dictionary

  5. 5

    How do I make a dictionary of events?

  6. 6

    How do I make ngFor for dictionary in Angular?

  7. 7

    How do I make ngFor for dictionary in Angular?

  8. 8

    How do i make a nested match in regex?

  9. 9

    I have nested lists as entries to a Python dictionary. How do I print the nested list whose first elements is "S"?

  10. 10

    I have nested lists as entries to a Python dictionary. How do I print the nested list whose first elements is "S"?

  11. 11

    How do I work with a nested dictionary's name?

  12. 12

    How do I append an element to an array in a nested dictionary

  13. 13

    How do you create a dictionary from nested lists in Python?

  14. 14

    how to sort nested dictionary python?

  15. 15

    How to create nested dictionary in python

  16. 16

    How do I make this nested for loop work faster

  17. 17

    How do I make a new array nested sorted maps?

  18. 18

    How to make a nested dictionary , IOS - Objective C

  19. 19

    How do I loop through a nested context dictionary in Django when I have no idea the structure I will recieve

  20. 20

    How do I make a dictionary with integers as keys out of dictionary with tuples as keys

  21. 21

    How do you make this shape in Python with nested loops?

  22. 22

    How do I make a python script executable?

  23. 23

    Numerical Python - how do I make this a ufunc?

  24. 24

    How do I make an object mutable in python?

  25. 25

    How do I make a float in Python?

  26. 26

    How do i make a game director in python?

  27. 27

    How do I make a grid in python?

  28. 28

    How do I make this python app installable?

  29. 29

    How do I make a timer in python?

HotTag

Archive