How to rename objects based on LODs in python script?
import bpy
name = 'Cube'  # case sensitive
collection_name = f'{name}.collection'
i = 0
obj = bpy.data.objects.get(name)
group = []
while obj: 
    # this loop assumes you don't have a missing object
    # (e.g. Cube, Cube.001, Cube.003 will not reach to the Cube.003)
    group.append(obj)
    i += 1
    obj = bpy.data.objects.get(f'{name}.{i:03d}')

'''lines 4-12 could be replaced with a single line below, but the line below
will match objects with names 'Cube.000', 'Cubes', 'Cube_copy' etc. as well
as it will go through all objects on the scene, which (rarely) could  be slow'''
# group = [o for o in bpy.data.objects if o.name.startswith(name)]

target_collection = bpy.data.collections.get(collection_name)
if not target_collection:
    target_collection = bpy.data.collections.new(collection_name)
    bpy.context.scene.collection.children.link(target_collection)

def sort_key(obj):
    obj.data.calc_loop_triangles()
    return len(obj.data.loop_triangles)

result = list(enumerate(sorted(group, key=sort_key), start=1))
    
for i, obj in result:
    obj.name = name + (f'_LOD{i}' if i&lt;len(result) else '') 
    for collection in obj.users_collection:
        collection.objects.unlink(obj)
    target_collection.objects.link(obj)


How to put similar named objects into collection in python?
Finding Vertices, Edges, Faces, and Tris using Python