Question about organized list of items from an empthy list

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.


# 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 = []

	for obj in self.scene_objs: 

		if obj.get('orbit') != None: 
			
			data = (obj.get('orbit'),obj.name)

			order_list.append(data)


	order_list.sort()

	print('Solar System objects ordered list succefull')

Thanks for answering Josip Kladaric, my thoughts were too directing me to the same code logic.

Also, adjusting the code to take into account only the name of the item after the sort, then it ended up this way:

	# 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 = []

		for obj in self.scene_objs: 

			if obj.get('orbit') != None: order_list.append( ( obj.get('orbit'), obj.name ) )


		g_variables.cur_s_system = [index[1] for index in sorted(order_list)]

		print('Solar System objects ordered list succefull')