I wish to do a summation like this:
tot_males = 0
tot_females = 0
for groups in itertools.chain.from_iterable(self.class): # Iterates over all the class
current_males, current_females = groups.number_of_persons() # Returns how many males and females there are in one group
tot_males += current_males
tot_females += current_females
return tot_males, tot_females # EDIT: Corrected return values
Is there any way to do this summation without a for loop? I am just curious. This is the best solution I have created so far.