I am using python 2.7.X version and I need to display my result of list of dictionary in key order same as in my output
CREATE THE LIST OF DICTIONARY :
for acc_data in acc_pool.browse(cr,uid,acc_ids_in):
for line in acc_data.invoice_line:
c+=1
lst_data2.append({
'SupplierName':acc_data.partner_id.name or '',
'SupplierBRN':acc_data.partner_id.com_reg_no1 or '',
'InvoiceDate':acc_data.date_invoice or '',
'InvoiceNumber':acc_data.number or '',
'ImportDeclarationNo':'',
'LineNumber':c,
'ProductDescription':line.product_id.name or '',
'PurchaseValueMYR':line.price_unit or 0.00,
'GSTValueMYR':'',
'TaxCode':line.invoice_line_tax_id.name or '',
'FCYCode':'',
'PurchaseFCY':'',
'GSTFCY':'',
})
RESULT ::
my result displaying from the ubuntu terminal
lst_data2 ==========>>>lst_data2 [{'ProductDescription': u'Ink Cartridge', 'SupplierBRN': '', 'ImportDeclarationNo': '', 'GSTValueMYR': '', 'SupplierName': u'Vicking Direct', 'GSTFCY': '', 'TaxCode': u'Purchase Tax 15.00%', 'InvoiceDate': '2015-03-24', 'FCYCode': '', 'PurchaseFCY': '', 'PurchaseValueMYR': 58.0, 'LineNumber': 1, 'InvoiceNumber': u'EXJ/2015/002'}, {'ProductDescription': u'Toner Cartridge', 'SupplierBRN': '', 'ImportDeclarationNo': '', 'GSTValueMYR': '', 'SupplierName': u'Vicking Direct', 'GSTFCY': '', 'TaxCode': u'OTAX X', 'InvoiceDate': '2015-03-24', 'FCYCode': '', 'PurchaseFCY': '', 'PurchaseValueMYR': 65.0, 'LineNumber': 2, 'InvoiceNumber': u'EXJ/2015/002'}]
hear u can easily see my key of order is different from in my result
My Question is that i need to set the all the keys from same as created in list of dictionary above from the list.
How can I set the same order of list of keys from in my result.??
use ordered dict. instead of regular dict. , visit this link to know use of order dict, http://pymotw.com/2/collections/ordereddict.html
@Mansi Kariya I have resolved that one from my side Be a Coooool ..... :) Thanks For Your Comment