Ex. Lets consider, I have a list,
list_var = ['sales_qty' , 'returns_qty' , 'net_sales_qty' , 'sales_amt' , 'returns_amt' ,'product_discount_amt' , 'product_net_amt' ,'product_cost_amt' , 'gross_sales_amt' , 'supplier_disc_amt' , 'category_disc_amt' , 'topup_disc_amt' , 'value_at_cost']
from this list element, i want to init these elements as list in the memory, so i could use append, extend method for these elements.
As follow,
#Need these variable in memory..
sales_qty = [], returns_qty = [], net_sales_qty = [] ... value_at_cost = []
#list operation on variable..
sales_qty.append(5)
Is there any simple way to do that, so i could remove element or add element in list easily?
You could create a dictionary of lists based on
list_var.Now can access your lists through the
list_dicdict:If you’re using a python version that does not support dict comprehensions (python 2.6 or lower), you can use a list comprehension instead (as DSM explained in his comment):