update_list_object.py 403 B

123456789101112131415161718192021
  1. #!/usr/bin/python
  2. cart = [
  3. {'id': 1, 'name': 'Product1', 'price': '2000', 'quantity': 0},
  4. {'id': 2, 'name': 'Product2', 'price': '3000', 'quantity': 0},
  5. {'id': 3, 'name': 'Product3', 'price': '4000', 'quantity': 0}
  6. ]
  7. print cart
  8. readed = {'id': 1, 'name': 'Product1', 'price': '2000', 'quantity': 0}
  9. print readed
  10. index = cart.index(readed)
  11. print index
  12. cart[index]['quantity'] += 1
  13. print cart