I have a list which contains a simple object of a class, say Person i.e:
my_list [Person<obj>, Person<obj> ..]
This Person object
is very simple, has various variables, values i.e:
Person_n.name = 'Philip'
Person_n.height = '180'
Person_n.lives_in = 'apartment'
So as you can see, all these Person
s live somewhere whether: apartment, house or boat.
What I want to create is a new list, or a dictionary (does not matter which) in which I have this list sorted in a way that they are grouped by their lives_in values and the most populated choice is the number one in the new list (or dictionary, in which lives_in value would be the key).
E.g.:
new_list = [('apartment', [Person_1, Person_5, Person_6, Person_4]), ('house': [Person_2, Peson_7]), ('boat': [Person_3])]
I am new to Python and I am stuck with endless loops. There must be a simple way to do this without looping through 4 times.
What is the Pythonic way to achieve this desired new list?