title: Adding the sorted elements in list
body: <p>I have a list ["Roll_Number","Marks in subjects"]:</p>
  
  <pre><code>list_1=[(1,22),(1,22),(2,29),(2,16),(3,56),(4,32),(4,12)]
  </code></pre>
  
  <p>I tried this code in python to get sum of all subjects for each roll_no :</p>
  
  <pre><code> sub_sum = [0] * 4 #Roll No :4
   if i in range(0,len(list1)):
   if k in range(0,5):
      if (list1[i][0]==k):
         sub_sum[k] = list1[i][1] + sub_sum[k]
         i=i+1
      else:
          k=k+1
          break
  </code></pre>
  
  <p>Getting an infinite loop.
  Expected Result : <code>1:44 , 2:45, 3:56 , 4:44</code>
  Thanks in advance.</p>