A
A
Alexander Pavlov2021-06-26 23:38:45
Python
Alexander Pavlov, 2021-06-26 23:38:45

How to pack a list into a list in Python?

Hello.

There is a dictionary in the list:

"items": [
    {
      "name": "ФЛУР.ДЕЛЮКС ШОК-КЛУБ",
      "price": 9900,
      "sum": 9900,
      "quantity": 1,
      "paymentType": 4,
      "productType": 1,
      "nds": 2
    },
    {
      "name": "ЛИМОНАД САНТОРИНИ",
      "price": 7900,
      "sum": 7900,
      "quantity": 1,
      "paymentType": 4,
      "productType": 1,
      "nds": 1
    },
    {
      "name": "СПРАЙТ БОЛЬШОЙ",
      "price": 7500,
      "sum": 7500,
      "quantity": 1,
      "paymentType": 4,
      "productType": 1,
      "nds": 1
    },
    {
      "name": "ФЛУРРИ ДЕЛЮКС ШОК-КАР",
      "price": 9900,
      "sum": 9900,
      "quantity": 1,
      "paymentType": 4,
      "productType": 1,
      "nds": 2
    }
  ]


I get what I need from there:
for item in files["items"]:
   name_product = item["name"]
   price = str(get_result_price(item["price"]))
   quantity = str(item["quantity"])
   amount = str(get_result_price(item["sum"]))


I need to make a list with lists so that it looks like this:


Tried like this:
for item in files["items"]:
            name_product = item["name"]
            price = str(get_result_price(item["price"]))
            quantity = str(item["quantity"])
            amount = str(get_result_price(item["sum"]))
            information_products.append(name_product)
            information_products.append(price)
            information_products.append(quantity)
            information_products.append(amount)


But it turns out not what is needed.

Tell me how to do it right?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vindicar, 2021-06-26
@Sanchez9891

1. form a list for the given element
itemlist = [name_product, price, quantity, amount]
2. add
information_products.append(itemlist) to this list I'm
surprised that this caused difficulties.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question