why have duplications in mu code using python
<p>I read from a xlsx file.
I'm trying to group by router column and add all mb coulmn. However, I have some duplications and I don`t know why?</p>

<p>Here is the code, can help me? </p>

<pre><code>def totalroutermb():
    arrayItems = items
    arrayItems2 = items
    arrayRouterAndMb = []
    num_mb = float(0.0)

    for user in arrayItems:
        for user2 in arrayItems2:
            if user.router == user2.router:
               num_mb += float(user2.download_in_mb)
               arrayItems2.remove(user2)
        dict = {"router": user.router, "Total": num_mb}
        arrayRouterAndMb.append(dict)

    for user in arrayRouterAndMb:
       print(user)
    print("\n")
</code></pre>

<p>And print this:</p>

<pre><code>{'router': 'Kut_2007_CO_Sag_a7:41', 'Total': 8861222409750.0}
{'router': 'Kut_2017_CO_Sol_e0:06', 'Total': 12448391550377.031}
{'router': 'Kut_Giris_AsansorSol_a7:3e', 'Total': 12460052878502.203}
{'router': 'Kut_Giris_AsansorSol_a7:3e', 'Total': 12460052878502.203}
{'router': 'Kut_Giris_AsansorSol_a7:3e', 'Total': 12470382956627.203}
{'router': 'Kut_Giris_Masa1_a4:82', 'Total': 18009186394127.203}
{'router': 'Kut_Kat1_Sag1_a9:3e', 'Total': 35296935066002.2}
{'router': 'Kut_Kat1_Sag1_a9:3e', 'Total': 35316851362878.78}
</code></pre>

<p>I solved it!! Sorry but I'm only few days with python, i'm learning</p>

<pre><code>def totalroutermb():
   arrayRouterAndMb = []

   for item in items:
      aux = [item.router.strip(), float(item.download_in_mb)]
      arrayRouterAndMb.append(aux)
   # order array
   arrayRouterAndMb.sort()

   # add all mb from each router
   arrayEachRouterMb = []
   pos = 0
   firstObj = arrayRouterAndMb[0]
   num_mb = firstObj[1]
   for obj in arrayRouterAndMb:
      pos += 1
      if pos == len(items):
         dict = {"Total": num_mb, "router": obj[0]}
         arrayEachRouterMb.append(dict)
         break
      objNext = arrayRouterAndMb[pos]
      if objNext[0] == obj[0]:
         num_mb += float(objNext[1])
      elif obj[0] != objNext[0]:
         dict = {"Total": num_mb, "router": obj[0]}
         arrayEachRouterMb.append(dict)
         num_mb = objNext[1]

   for user in arrayEachRouterMb:
      print(user)
   print("\n")
</code></pre>

python python-3.x