Python Forum
From flat to nested structure
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
From flat to nested structure
#3
Hey nilamo,

Thanks for that - I was able to achieve similar result by using defaultdict. After splitting key-values on colon I created and zipped two list with keys and corresponding values and then:

grouped = defaultdict(list)
for key, val in record:
     grouped[key].append(val)
But if I associate recurrent keys with all its values I cannot see the way of differentiating single records, say one from from 'a' to 'd' and second from 'a' to 'e'. How do you know if 'e' belongs to first or second record? All values will be clustered around single keys. My aim here is to construct JSON out of input data and I cannot see an easy way of producing that out of values grouped around single keys.
Reply


Messages In This Thread
From flat to nested structure - by CptHaddock - Mar-19-2018, 08:20 PM
RE: From flat to nested structure - by nilamo - Mar-19-2018, 08:46 PM
RE: From flat to nested structure - by CptHaddock - Mar-19-2018, 09:33 PM
RE: From flat to nested structure - by nilamo - Mar-20-2018, 03:57 PM
RE: From flat to nested structure - by CptHaddock - Mar-21-2018, 07:31 PM
RE: From flat to nested structure - by nilamo - Mar-21-2018, 07:50 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  I’m Flat out struggling to understand list indexes gr3yali3n 7 2,975 Jul-20-2020, 07:18 PM
Last Post: princetonits
  Nested Data structure question arjunfen 7 4,310 Feb-22-2019, 02:18 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

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