Python Forum
convert list of dict to dict of array of list with pop up
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
convert list of dict to dict of array of list with pop up
#1
Hi All,

Need help to convert the input dictionary to o/p below format

input:
[{'type': 'cummulative', 'environment': None, 'domain': 'ARRAW', 'total_hits': 7, 'success': 1, 'failure': 6},
 {'type': 'cummulative', 'environment': None, 'domain': 'WQAT', 'total_hits': 33, 'success': 26, 'failure': 7}, 
 {'type': 'environment', 'environment': 'ACP', 'domain': 'WQAT', 'total_hits': 11, 'success': 11, 'failure': 0}, 
 {'type': 'environment', 'environment': 'DIT', 'domain': 'ARRAW', 'total_hits': 7, 'success': 1, 'failure': 6}, 
 {'type': 'environment', 'environment': 'DIT', 'domain': 'WQAT', 'total_hits': 11, 'success': 4, 'failure': 7}, 
 {'type': 'environment', 'environment': 'INT', 'domain': 'WQAT', 'total_hits': 11, 'success': 11, 'failure': 0}]
required O/P:
 {	WQAT:[{cummulative:[{'environment': None, 'domain': 'WQAT', 'total_hits': 33, 'success':26, 'failure': 7}],
	     environment: [{'environment':'ACP', 'domain': 'WQAT', 'total_hits': 11, 'success': 11, 'failure': 0},
						{'environment': 'DIT', 'domain': 'WQAT', 'total_hits': 11, 'success': 4, 'failure': 7}, 
					    {'environment': 'INT', 'domain': 'WQAT', 'total_hits': 11, 'success': 11, 'failure': 0}]
  ARRAW: [{cummulative:[{'environment': None, 'domain': 'ARRAW', 'total_hits': 7, 'success': 1, 'failure': 6}],
	     environment: [ {'environment': 'DIT', 'domain': 'ARRAW', 'total_hits': 7, 'success': 1, 'failure': 6}]
}
Reply
#2
First of all - what have you tried?

Second - is this output you actually want? Can you describe in spoken language based on what the new structure is built-up.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Convert numpy array to image without loading it into RAM. DreamingInsanity 7 5,727 Feb-08-2024, 09:38 AM
Last Post: paul18fr
  Unpacking a dict with * or ** msrk 4 919 Dec-02-2023, 11:50 PM
Last Post: msrk
  Why does newly-formed dict only consist of last row of each year? Mark17 6 744 Nov-17-2023, 05:28 PM
Last Post: Mark17
  dict table kucingkembar 4 663 Sep-30-2023, 03:53 PM
Last Post: deanhystad
  No matter what I do I get back "List indices must be integers or slices, not list" Radical 4 1,091 Sep-24-2023, 05:03 AM
Last Post: deanhystad
  Convert np Array A to networkx G IanAnderson 2 629 Jul-05-2023, 11:42 AM
Last Post: IanAnderson
  Delete strings from a list to create a new only number list Dvdscot 8 1,466 May-01-2023, 09:06 PM
Last Post: deanhystad
  replacing dict contents Skaperen 6 1,147 Apr-16-2023, 05:57 PM
Last Post: Skaperen
  search in dict inside tuple steg 1 648 Mar-29-2023, 01:15 PM
Last Post: rob101
  Partial KEY search in dict klatlap 6 1,200 Mar-28-2023, 07:24 AM
Last Post: buran

Forum Jump:

User Panel Messages

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