# Difference between results (Python and Dictionaries)

**URL:** <https://forum.dynamobim.com/t/difference-between-results-python-and-dictionaries/15320>\
**Category:** Developers\
**Created:** [October 3, 2017, 8:37pm UTC](https://forum.dynamobim.com/t/difference-between-results-python-and-dictionaries/15320 "2017-10-03T20:37:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jorge\_Villarroel](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jorge_villarroel/32/23619_2.png) [@Jorge\_Villarroel](https://forum.dynamobim.com/u/Jorge_Villarroel)\
**Post date:** [October 3, 2017, 8:37pm UTC](https://forum.dynamobim.com/t/difference-between-results-python-and-dictionaries/15320/1 "2017-10-03T20:37:37Z")

</div>

Hi there,

I’m experiencing some troubles with dictionaries in python (i read that in dynamo there are some limitations to work with them in python) but I’m not sending a dictionary into the OUTPUT, so I think there is no error here.

The issue is that I developed the code in an online interpreter ([https://repl.it/MB3v/14](https://repl.it/MB3v/14)), and I’m getting this result for **AUX** :

![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/b/9/b9612d34f6c4bb3de592754fe5e668d4918178de.png)

but if I take **the same** code into a python node, i get this:

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/5/3/5392c1b5976abf9fa74f124d6e6ea83dc9cd24c4.png)

This is the code:

```
lineas = []
lineas.append(['c' , 0 , 470 ,0])
lineas.append(['c' , 255 , 410 ,70])
lineas.append(['c' , 135 , 255 ,160])
lineas.append(['c' , 410 , 470 ,160])
lineas.append(['c' , 0 , 135 ,300])

# Lineas cargadas 
# Diccionario con la cantidad de segmentos por z
segmentosPiso = {}
for x in range(0,len(lineas)):
    segmentosPisoObjetoLocal = {}
    if lineas[x][3] in segmentosPiso.keys():
      segmentosPiso[lineas[x][3]] = segmentosPiso[lineas[x][3]] + 1
    else:
      segmentosPiso[lineas[x][3]] = 1

lineasCargadas = {}
contador = 0
iCoun = 0
AUX = []
for k,v in segmentosPiso.items():
    lineasADibujar = []
    if ((contador > 0) and (contador < len(segmentosPiso) - 1)):
        # print (k,v)
        ind = []
        for lline in range(0,len(lineas)):
          if (k == lineas[lline][3]):
            ind.append(lline)
        for c in ind:
            lineasCargadas[iCoun] = (c)
            iCoun +=1
        # print(lineasCargadas)
        for xline in range(1,len(lineas)):
          bFlag = False
          for xCar , xVal in lineasCargadas.items():
            if((lineas[xline][1] == lineas[xVal][1]) and (lineas[xline][2] == lineas[xVal][2])):
              bFlag = True
          if bFlag == False:
            lineasADibujar.append(xline)
        AUX.append(lineasADibujar)
        # print(lineasADibujar)    
    #bflag = False
    contador += 1

```

I really don’t get where is the error or what am I missing here.

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![Jorge\_Villarroel](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jorge_villarroel/32/23619_2.png) [@Jorge\_Villarroel](https://forum.dynamobim.com/u/Jorge_Villarroel)\
**Post date:** [October 4, 2017, 12:24pm UTC](https://forum.dynamobim.com/t/difference-between-results-python-and-dictionaries/15320/2 "2017-10-04T12:24:39Z")

</div>

Finnally we came with a solution:

```
lineas = {}
lineas[0] = ['c' , 0 , 470 ,0]
lineas[1] = ['c' , 255 , 410 ,70]
lineas[2] = ['c' , 135 , 255 ,160]
lineas[3] = ['c' , 410 , 470 ,160]
lineas[4] = ['c' , 0 , 135 ,300]

# Lineas cargadas
# Diccionario con la cantidad de segmentos por z
lineas = PaqueteLimites
segmentosPiso = {}
for x in range(0,len(lineas)):
    segmentosPisoObjetoLocal = {}
    if lineas[x][3] in segmentosPiso.keys():
      segmentosPiso[lineas[x][3]] = segmentosPiso[lineas[x][3]] + 1
    else:
      segmentosPiso[lineas[x][3]] = 1

segPiso = []
for k,v in segmentosPiso.items():
    segPiso.append([k,v])

lineasCargadas = []
contador = 0
aux = []
for info in range(0,len(segPiso)):
    if ((contador > 0) and (contador < len(segmentosPiso) - 1)):
        lineasADibujar = []
        ind = []
        for lline in range(0,len(lineas)):
          if (segPiso[info][0] == lineas[lline][3]):
            ind.append(lline)
        for indiceCargado in ind:
            lineasCargadas.append(indiceCargado)
        for xline in range(1,len(lineas)):
          bFlag = False
          for xVal in range(0,len(lineasCargadas)):
            if((lineas[xline][1] == lineas[lineasCargadas[xVal]][1]) and (lineas[xline][2] == lineas[lineasCargadas[xVal]][2])):
              bFlag = True
          if bFlag == False:
            lineasADibujar.append(xline)
        aux.append(lineasADibujar)
    contador += 1

```

We changed dictionaries into lists and still got the same result. Then, we realized that **segPiso** wasn’t in the order wanted, so we added **segPiso = sorted(segPiso)** after it’s definition, and the problem was solved.

```
lineas = {}
lineas[0] = ['c' , 0 , 470 ,0]
lineas[1] = ['c' , 255 , 410 ,70]
lineas[2] = ['c' , 135 , 255 ,160]
lineas[3] = ['c' , 410 , 470 ,160]
lineas[4] = ['c' , 0 , 135 ,300]

segPiso = []
for k,v in segmentosPiso.items():
segPiso.append([k,v])
segPiso = sorted(segPiso)

lineasCargadas = []
contador = 0
IndicesCurvas = []
for info in range(0,len(segPiso)):
if ((contador > 0) and (contador < len(segmentosPiso) - 1)):
    lineasADibujar = []
    ind = []
    for lline in range(0,len(lineas)):
      if (segPiso[info][0] == lineas[lline][3]):
        ind.append(lline)
    for indiceCargado in ind:
        lineasCargadas.append(indiceCargado)
    for xline in range(1,len(lineas)):
      bFlag = False
      for xVal in range(0,len(lineasCargadas)):
        if((lineas[xline][1] == lineas[lineasCargadas[xVal]][1]) and (lineas[xline][2] == lineas[lineasCargadas[xVal]][2])):
          bFlag = True
      if bFlag == False:
        lineasADibujar.append(xline)
    IndicesCurvas.append(lineasADibujar)
contador += 1

```

But still, don’t really know why the problem of the order or the dictionary not working. Any suggestions?

Thanks!

---

<div class="post-metadata">

**Author:** ![Gui\_Talarico](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/gui_talarico/32/10887_2.png) [@Gui\_Talarico](https://forum.dynamobim.com/u/Gui_Talarico)\
**Post date:** [October 4, 2017, 12:43pm UTC](https://forum.dynamobim.com/t/difference-between-results-python-and-dictionaries/15320/3 "2017-10-04T12:43:15Z")

</div>

Python dictionary are unordered data types.  
For a dictionary that keeps items ordered you need the OrderedDict from the collections module.

---

<div class="post-metadata">

**Author:** ![Jorge\_Villarroel](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jorge_villarroel/32/23619_2.png) [@Jorge\_Villarroel](https://forum.dynamobim.com/u/Jorge_Villarroel)\
**Post date:** [October 4, 2017, 12:44pm UTC](https://forum.dynamobim.com/t/difference-between-results-python-and-dictionaries/15320/4 "2017-10-04T12:44:03Z")

</div>

Thanks @Gui_Talarico. I’ll keep this in mind!
