Sometimes it makes sense to cluster related data together. I tend to do so with a dict, e.g.,
group = dict(a=1, b=2, c=3)
print(group['a'])
One of my colleagues prefers to create a class
class groupClass:
def __init__(self, a, b, c):
self.a = a
self.b = b
self.c = c
group = groupClass(1, 2, 3)
print(group.a)
Note that we are not defining any class methods.
I like to use a dict because I like to minimize the number of lines of code. My colleague thinks the code is more readable if you use a class, and it makes it easier to add methods to the class in the future.
Which do you prefer and why?
print self.group['a']
– Pentheam