Hi, I have this code below:
# Function to arrange a solar system bodies in an ordered list
def arrange_orbits_list(self):
print('Arranging Solar System objects in an ordered list')
order_list = []
content_list = []
for obj in self.scene_objs:
if obj.get('orbit') != None:
order_list.append(obj.get('orbit'))
content_list.append(obj.name)
g_variables.cur_s_system = [index[1] for index in sorted(zip(order_list, content_list))]
print('Solar System objects ordered list succefull')
Its logic is which it should search for any object with the ‘orbit’ property(which contains a int value), and put all the objects found into an ordered list, being which the order is based on the ‘orbit’ value of each object, but the real index item for each index in that list is the object name.
Is there a better way of doing the above? I tried to use directly in the first for loop a list.insert( orbit value, item.name)(which would save a few code lines), but that gave wrongly ordered results, as I thought which inserting ( 5, item.name) for example into an empthy list would return [0,0,0,0,0, item.name], but it didn’t. Does python have something which can add zeros to a list if the index it will work upon still does not exist?
Thanks for any guidance.