While prototyping in Python, I relied on lists of lists and the operator class's .itemgetter method to do the sorting. &nbsp;The idea behind this is that Python would sort lists within lists based on the index specified.<br><br>While I am absolutely terrible at wrapping my head around things like Big O Notation, I did type out this straightforward bit of code to sort lists of lists. &nbsp;<br><br>The lists I am trying to sort are in the below format and it is assumed that you are sorting by the 1st index as suggested by the magic number within the code. &nbsp;This magic number simply needs to be changed to sort by another index. &nbsp;In this example, the only other option would be the 0th index, which would then sort the strings.<br><br>[ [string,int] , [string,int] , [string,int] ] etc.<br><br>************************************THE CODE************************************<br><br>

var sorted_parent_list = [] # empty until the code runs<br>var parent_list = (list formatted as above)<br>func sort_listed_lists():<br> var sorted_values_of_index_1&nbsp;= [] <br>#The following loop takes all of the index 1 values and sorts them, putting them in<br>#In this example, the list called sorted_values_of_index_1, as above.<br> for child_list in parent_list:<br> sorted_values_of_index_1.append(child_list[1]) # The magic number<br> sorted_values_of_index_1.sort()<br>#The following loop takes all of the items in the list created in the function above<br>#sorted_values_of_index_1<br>#A nested loop then looks at all of the child lists within the main unsorted parent list, or 'original list of lists'<br>#If the integer from the sorted integers matches the integer in the original list<br>#That list containing the matching integer is added to the sorted_parent_list<br>for sorted_integer in sorted_values_of_index_1:<br>tab&gt;for list in parent_list:<br>tab&gt;tab&gt;if sorted_integer == list[1]:<br>tab&gt;tab&gt;tab&gt;sorted_parent_list.append([list[0],sorted_integer])<br>tab&gt;sorted_values_of_index_1.remove(sorted_integer)<br>print(sorted_parent_list)
9 days later

Thanks for all the contribution but to make it even nicer you could use the 'Format' button of the text box when posting, there's a 'hidden' 'code' button in there, just select the code you want to share, press it and voila, code highlighting in the posts :P. Like so:<br><br>

onready var = self.get_node('path/to/node')

<p><br></p>

25 days later

thanks for this tuto 1000h, but when I run the program, godot close it, and tells me: "Parser Error: Identifier not found: sorted_roll" I have missed something, someone just help me? Thank you ! :)

@LOIC said: thanks for this tuto 1000h, but when I run the program, godot close it, and tells me: "Parser Error: Identifier not found: sorted_roll" I have missed something, someone just help me? Thank you ! :)

I think I should have written sorted_integer there and not sorted_roll, just made mistake in typing the variable name. Also the indentation is probably a little messed up, apologies