Browse Source

update list object

robert2206 8 years ago
commit
82385fe9ef
1 changed files with 21 additions and 0 deletions
  1. 21 0
      update_list_object.py

+ 21 - 0
update_list_object.py

@@ -0,0 +1,21 @@
+#!/usr/bin/python
+
+cart = [
+	{'id': 1, 'name': 'Product1', 'price': '2000', 'quantity': 0},
+	{'id': 2, 'name': 'Product2', 'price': '3000', 'quantity': 0}, 
+	{'id': 3, 'name': 'Product3', 'price': '4000', 'quantity': 0}
+]
+
+print cart
+
+readed = {'id': 1, 'name': 'Product1', 'price': '2000', 'quantity': 0}
+
+print readed
+
+index = cart.index(readed)
+
+print index
+
+cart[index]['quantity'] += 1
+
+print cart