Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
group by property
#26
(Jul-01-2019, 06:43 PM)bhojendra Wrote: As in my initial post, I want the result as like:

I asked why you want result like that? What are the benefits of new structure over old one?

old = [{'name': 'John', 'm': 'good', 'n': 1},
       {'name': 'Alina','m': 'good', 'n': 1},
       {'name': 'Olivia', 'm': 'bad', 'n': 2},
       {'name': 'Ruby', 'm': 'bad','n': 2}]

new = [{'g': [{'name': 'John', 'n': 1}, {'name': 'Alina', 'n': 1}]},
       {'b': [{'name': 'Olivia','n': 2},{'name': 'Ruby','n': 2}]}]
Old list dictionaries have exactly the same structure, new list dictionaries not (some have key 'g', some key 'b' and some probably both). You must be extra careful to not run into KeyError while accessing data.
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


Messages In This Thread
group by property - by bhojendra - Jun-30-2019, 05:08 AM
RE: group by property - by SheeppOSU - Jun-30-2019, 05:16 AM
RE: group by property - by bhojendra - Jun-30-2019, 05:35 AM
RE: group by property - by SheeppOSU - Jun-30-2019, 06:06 AM
RE: group by property - by bhojendra - Jun-30-2019, 06:19 AM
RE: group by property - by SheeppOSU - Jun-30-2019, 06:27 AM
RE: group by property - by scidam - Jun-30-2019, 12:00 PM
RE: group by property - by bhojendra - Jun-30-2019, 12:25 PM
RE: group by property - by SheeppOSU - Jun-30-2019, 12:45 PM
RE: group by property - by bhojendra - Jun-30-2019, 01:12 PM
RE: group by property - by SheeppOSU - Jun-30-2019, 01:29 PM
RE: group by property - by bhojendra - Jun-30-2019, 01:32 PM
RE: group by property - by SheeppOSU - Jun-30-2019, 01:51 PM
RE: group by property - by bhojendra - Jun-30-2019, 01:54 PM
RE: group by property - by SheeppOSU - Jun-30-2019, 02:03 PM
RE: group by property - by bhojendra - Jun-30-2019, 02:16 PM
RE: group by property - by SheeppOSU - Jun-30-2019, 02:25 PM
RE: group by property - by bhojendra - Jun-30-2019, 03:00 PM
RE: group by property - by SheeppOSU - Jun-30-2019, 03:14 PM
RE: group by property - by bhojendra - Jun-30-2019, 03:32 PM
RE: group by property - by SheeppOSU - Jun-30-2019, 03:55 PM
RE: group by property - by perfringo - Jul-01-2019, 07:26 AM
RE: group by property - by bhojendra - Jul-01-2019, 08:23 AM
RE: group by property - by perfringo - Jul-01-2019, 11:04 AM
RE: group by property - by bhojendra - Jul-01-2019, 06:43 PM
RE: group by property - by perfringo - Jul-01-2019, 08:45 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Subclass initialized property used in parent class method. Is it bad coding practice? saavedra29 5 1,941 Feb-07-2022, 07:29 PM
Last Post: saavedra29
  ABC Module and @property decorator, Pythonic Way? muzikman 21 5,944 Aug-18-2021, 06:08 PM
Last Post: muzikman
  @property vs __set__ / __get__ and __setattr__ / __getattr__ okhajut 1 3,436 Jun-15-2021, 03:48 PM
Last Post: snippsat
  Can property getters and setters have additional arguments? pjfarley3 2 3,114 Oct-30-2020, 12:17 AM
Last Post: pjfarley3
  Property price calculation oli_action 4 3,253 Jul-15-2020, 04:27 PM
Last Post: sridhar
  Use of @property decorator ruy 16 6,812 Jun-09-2020, 05:29 PM
Last Post: buran
  Problem adding keys/values to dictionary where keynames = "property" and "value" jasonashaw 1 2,101 Dec-17-2019, 08:00 PM
Last Post: jasonashaw
  strange class property KaliLinux 2 2,420 Nov-25-2019, 04:32 PM
Last Post: KaliLinux
  print all method and property of list object engmoh 4 2,946 Oct-26-2019, 05:33 PM
Last Post: engmoh
  what is the doc parameter of property? microphone_head 2 2,526 Apr-11-2019, 08:59 AM
Last Post: microphone_head

Forum Jump:

User Panel Messages

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