title: How to avoid 2 equal loopings | Django
body: <p>I got this code:</p>
  <pre><code>    i = 1
      for item in cart:
          data_ps[f&quot;itemId{i}&quot;] = item
          data_ps[f&quot;itemDescription{i}&quot;] = item.category.name
          data_ps[f&quot;itemAmount{i}&quot;] = item.sell_price
          data_ps[f&quot;itemQuantity{i}&quot;] = '1'
          i += 1
  
      total_value = format(((shipping_price + cart_price) / installment), '.2f')
      data_ps['installmentValue'] = total_value
  
      response = requests.post('https://ws.sandbox.pagseguro.uol.com.br/v2/transactions', headers=headers,
                               params=params, data=data_ps)
  
      if response.status_code == 200:
          for item in cart:
              Sell.objects.create(item=item,
                                  date=timezone.now(),
                                  discount=Decimal(0.00),
                                  total_paid=cart.get_total_price(),
                                  buyer=request.user, )
  </code></pre>
  <p>As you can see, there are 2 <code>for item in cart</code> loop. After the first one, I need to get a request.post and then check if the status_code is equal 200. If so, the code gerenates another <code>for item in cart</code> loop.</p>
  <p>I was wondering if there is a way to avoid the second looping adding all this information inside the first one, because it just update a record in my database ('Sell.objects.create').</p>
  <p>Any idea?</p>
  <p>Thank you</p>