Python sorting script bug or my error?

I have created a python script for dual sorting, it needs to sort by one first condition then do a secondary sort without effecting the arrangement of the primary sort condition.

 

The issue i am having is that it doesnt always sort correctly on the secondary sort which you will be able to see on the image and the python code is below.

 

Image link as i couldnt upload to here(will change later):

https://photos-1.dropbox.com/t/2/AABVnW4DR1hbkN0XyjIhCLEDem7ajT0VnDgdOrV74DzlZQ/12/17332191/png/32x32/1/1435154400/0/2/python%20script%20error%20or%20bug.png/CN_voQggASACIAMgBCAFIAYgBygBKAI/H_eTteS28Lqz3--lgcbjpX97-87WryR4pvoESNcfRpE?size_mode=5

 

Any advice or help would be greatful as this is my first python code.

 

[quote]

<span style=“color: #f92672; font-weight: bold;”>import</span> clr
clr.<span style=“color: #ffffff; font-weight: bold;”>AddReference</span>(<span style=“color: #e6db74;”>‘ProtoGeometry’</span>)
<span style=“color: #f92672; font-weight: bold;”>from</span> Autodesk.DesignScript.Geometry <span style=“color: #f92672; font-weight: bold;”>import</span> *

<span style=“color: #75715e;”>#The inputs to this node will be stored as a list in the IN variable.</span>
list_el = IN[<span style=“color: #ae81ff;”>0</span>]
orientation = IN[<span style=“color: #ae81ff;”>1</span>]
output = []

<span style=“color: #f92672; font-weight: bold;”>if</span> orientation == True:
output = <span style=“color: #ffffff; font-weight: bold;”>sorted</span>(list_el, key=<span style=“color: #f92672; font-weight: bold;”>lambda</span> list_el:(list_el[<span style=“color: #ae81ff;”>1</span>], -list_el[<span style=“color: #ae81ff;”>2</span>]), reverse=True)
<span style=“color: #f92672; font-weight: bold;”>else</span>:
output = <span style=“color: #ffffff; font-weight: bold;”>sorted</span>(list_el, key=<span style=“color: #f92672; font-weight: bold;”>lambda</span> list_el:(list_el[<span style=“color: #ae81ff;”>2</span>], list_el[<span style=“color: #ae81ff;”>1</span>]))

<span style=“color: #75715e;”>#Assign your output to the OUT variable</span>
OUT = output

[quote]

Hour are you wanting to sort your data? This may be possible with OOTB Dynamo nodes.

 

Dam i cannot modify my post above, to add the below images.

 

I am after the the set of numbers that you will in the below image, to be organised dependant on a boolean outcome.

 

If boolean was true it would need to organise by highest first number then lowest second numbers.

 

If false it does by lowest second number then highest first number.

 

 

 

 

view of watch node
python script error or bug

 

 

 

 

 

 

 

 

Script

python script

You could definitely do something similar with the default nodes. Tho a python approach might be neater:

2015-06-25_12-01-16

Cheers for that, but if you notice on the middle watch node it seems to have messed up the origanal order(first sort). now has a number 8 from the first sort second when it should still be a number 9.

 

Python may be the way to go, if python or dynamo does have this little bug in it. I may have to do first sorting then split the lists out do another sort then restitch them together.

 

What are your thoughts on this. I kn0w i probably will have to do something similar for a another sort once i get all sub components of the origanal item.

The big numbers are under index 1 ( >=10) and the small numbers are under index 2 (<=9). In the mid watch node(the one sorted by the big numbers list) 8 is after 9 because 10 is before 11. Hope that makes sense :smiley:

OK thanks I think I have it and if you wanted the second list to sort highest to lowest could this be done with the sort nodes