SatyanarayanaMEthuku

python list of dictinories category name wise separate

May 17th, 2020
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.37 KB | None | 0 0
  1.  
  2. dic=[{'category_name':'tv',"price":3000,"model":"1.2"},
  3. {"category_name":"mobile", "price":8900,"model":"1.6"},
  4. {'category_name':'tv',"price":5000, "model":"1.8"},
  5. {'category_name':'soaps',"price":8000,"model":"1.9"}]
  6.  
  7.  
  8.  
  9. data={}
  10. for x in dic:
  11. if x['category_name'] not in data:
  12. data[x['category_name']]={}
  13. else:
  14. pass
  15.  
  16. print(data)
Add Comment
Please, Sign In to add comment