title: How to calculate the marks for each group and deduce the average score under each group,
body: <p><strong>UPDATED QUESTION AND CODE!30.01.2021</strong></p>
  <p>This question logically came up after this question - <a href="https://stackoverflow.com/questions/65844300/how-to-find-a-separate-attribute-among-the-records-and-form-a-separate-collectio">How to find a separate attribute among the records and form a separate collection on it?</a></p>
  <p>I need to calculate the average score of each group.
  In the code that the user @itprorh66 suggested, I added a formula for calculating the average score(it works) and a conditional search operator for the grade.</p>
  <p>Mister  @itprorh66<br />
  I decided to modify your code a bit to try to solve my problem myself. But so far unsuccessful.</p>
  <p>This code block is working</p>
  <pre><code>def srtgr(self):
            counthrees=0
            countfours=0
            countfives=0
            midl_average=0      
            gl=dict()    #Dictionary for the group      
            for s in studinfos:
                 sd=gl.pop(s.numbgroup,dict())
                 sd[s.surn]=[s.markgeometry,s.markalgebra,s.markinformatika]
                 gl[s.numbgroup]=sd
            for k,v, in gl.items():                  
                      s=f'Group: {k}: \n'
                      for stdn,grds in v.items():                  
                            s+=f'  {stdn}\t{grds[0]},{grds[1]},{grds[2]} \n'
                      print(s)
  </code></pre>
  <p>This is the second part in <code>def srtgr</code>. In this code block I trying to calculate the number of grades (3,4 and 5) in each group, and then find the average grade for each group. With the help of a loop, I start traversing the dictionary and with the help of the branch operator I start counting the scores in each group, but that's what I thought when I wrote this code. In reality, nothing starts and does not count</p>
  <pre><code>for grds in gl.items():
                   if grds.markgeometry==3:
                        counthrees+=1
                   if grds.markalgebra==3:
                        counthrees+=1
                   if grds.markinformatika==3:
                        counthrees+=1
                   if grds.markgeometry==4:
                        countfours+=1
                   if grds.markalgebra==4:
                        countfours+=1
                   if grds.markinformatika==4:
                        countfours+=1
                   if grds.markgeometry==5:
                        countfives+=1
                   if grds.markalgebra==5:
                        countfives+=1
                   if grds.markinformatika==5:
                        countfives+=1
                   midl_average = (counthrees+countfours+countfives)/3
                   for kk,grds1 in gl.items():                  
                      grds=f'Group: {kk}: {grds1}\n'
                      print(grds)
            print(*sorted(gl, key = midl_average, reverse = True))
  </code></pre>
  <p><strong>INPUT DATA</strong></p>
  <p>My reputation is litlle and I can not add the picture form my computer and I send the link,where my input data, what I add in class and how my object classes collection showing in the console. And the separated of groups</p>
  <p><a href="https://ibb.co/zV1B0HC" rel="nofollow noreferrer">https://ibb.co/zV1B0HC</a></p>
  <p>How to make it so that the average grade is displayed at the bottom after the list of students in each group?
  Or just calculate the average score in each group and enter it into another dictionary?</p>
  <p>I figured out the sorting of values ​​in the dictionary.</p>
  <p>I tried to make a 2nd dictionary and put the groups there, and then calculate it in a separate assessment unit - it didn't work.
  Then I read that in Python you can add a dictionary to a dictionary.
  As a result, I tried to add the existing dictionary to the new one, but did not understand how to proceed.
  Because grades must be calculated anyway</p>
  <p>You cannot use any helper classes, work with only one class.</p>