Python Forum
pop default of two list of dictionary
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
pop default of two list of dictionary
#1
Hi team,

I have two list of dictionary, we need below output format. kindly help us.

list1 = [{'type': 'cumulative', 'domain': 'NEED', 'success': 26, 'failure': 7}]
list2 =  [{'type': 'environment', 'environment': 'ACP', 'domain': 'NEED', 'total_hits': 11, 'success': 11, 'failure': 0}, {'type': 'environment', 'environment': 'DIT', 'domain': 'NEED', 'total_hits': 11, 'success': 4, 'failure': 7}, {'type': 'environment', 'environment': 'INT', 'domain': 'NEED', 'total_hits': 11, 'success': 11, 'failure': 0},
{'type': 'environment', 'environment': 'ACP', 'domain': 'FEED', 'total_hits': 11, 'success': 11, 'failure': 0}, {'type': 'environment', 'environment': 'DIT', 'domain': 'FEED', 'total_hits': 11, 'success': 4, 'failure': 7}, {'type': 'environment', 'environment': 'INT', 'domain': 'FEED', 'total_hits': 11, 'success': 11, 'failure': 0}]
O/P Required :
Pop default should be "domain" and "type
Output:
{ NEED: { cumulative :[{ 'success': 26, 'failure': 7 }], environment : [ ACP : {'total_hits': 11, 'success': 11, 'failure': 0 }, DIT : {'total_hits': 11, 'success': 4, 'failure': 7 }, INT : {'total_hits': 11, 'success': 11, 'failure': 0 } ] }, FEED: { environment : [ ACP : {'total_hits': 11, 'success': 11, 'failure': 0 }, DIT : {'total_hits': 11, 'success': 4, 'failure': 7 }, INT : {'total_hits': 11, 'success': 11, 'failure': 0 } ] } }
Reply
#2
The syntax of your output is not valid Python, and your question is so vague and odd (pop doesn't have a default) that I'm not sure what even looking for. My guess is that you would want to start with this dictionary:

data = {'NEED': {'cumulative': [], 'environment': {}}, 'FEED': {'cumulative': [], 'environment': {}}}
The you would loop through your lists and use conditionals to figure out which slot to add each dictionary in the list to, and whether it would be added with an append or an assignment to a dictionary key.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Dictionary in a list bashage 2 541 Dec-27-2023, 04:04 PM
Last Post: deanhystad
  filtering a list of dictionary as per given criteria jss 5 666 Dec-23-2023, 08:47 AM
Last Post: Gribouillis
  Sort a list of dictionaries by the only dictionary key Calab 1 488 Oct-27-2023, 03:03 PM
Last Post: buran
  How to add list to dictionary? Kull_Khan 3 998 Apr-04-2023, 08:35 AM
Last Post: ClaytonMorrison
  List of Modules/Libraries Installed by Default? rontarrant 2 999 Oct-14-2022, 05:18 PM
Last Post: rontarrant
  check if element is in a list in a dictionary value ambrozote 4 1,963 May-11-2022, 06:05 PM
Last Post: deanhystad
  Dictionary from a list failed, help needed leoahum 7 1,956 Apr-28-2022, 06:59 AM
Last Post: buran
  how to assign items from a list to a dictionary CompleteNewb 3 1,567 Mar-19-2022, 01:25 AM
Last Post: deanhystad
  Python, how to manage multiple data in list or dictionary with calculations and FIFO Mikeardy 8 2,596 Dec-31-2021, 07:47 AM
Last Post: Mikeardy
  Class-Aggregation and creating a list/dictionary IoannisDem 1 1,917 Oct-03-2021, 05:16 PM
Last Post: Yoriz

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020