Home > front end >  How to loop through an array in python
How to loop through an array in python

Time:09-13

how to loop through this array and display the values en python

 {"products":[
    {
      "desi":"kakakaka",
      "price":1400
    },
    {
      "desi":"mamama",
      "price":5000
    },
 ]
 }

CodePudding user response:

You can try something like this:

data =  {"products":[
    {
      "desi":"kakakaka",
      "price":1400
    },
    {
      "desi":"mamama",
      "price":5000
    },
 ]
 }
 
array = data['products']
 
for item in array:
    print(item)

CodePudding user response:

dict = {
    "products": [
        {
            "desi": "kakakaka",
            "price": 1400
        },
        {
            "desi": "mamama",
            "price": 5000
        },
    ]
}

for product in dict["products"]:
    print(product)

Output:

{'desi': 'kakakaka', 'price': 1400}
{'desi': 'mamama', 'price': 5000}
  • Related