Finding the lists of connected indices associated with disjoint mesh elements
I'll give an alternative answer based on your own answer.

This slightly modified version of your script assumes the active object is appropriate for the operation. something like:



with bmesh:

import bpy
import bmesh

obj = bpy.context.active_object

bpy.ops.object.mode_set(mode='EDIT', toggle=False) # Go to edit mode
bpy.ops.mesh.select_all(action="DESELECT") # unselect everything

bm = bmesh.from_edit_mesh(obj.data) # load mesh
bm.faces.ensure_lookup_table()

loops = []
faces = bm.faces

while faces:
    faces[0].select_set(True) # select 1st face
    bpy.ops.mesh.select_linked() # select all linked faces makes a full loop
    loops.append([f.index for f in faces if f.select])
    bpy.ops.mesh.hide(unselected=False) # hide the detected loop
    faces = [f for f in bm.faces if not f.hide] # update faces

bpy.ops.mesh.reveal() # unhide all faces
print("Mesh has {} parts".format(len(loops)))

print("\nThe face lists are:")
for loop in loops:
    print(loop)


The output of the script is visisble from commandline/console

Mesh has 5 parts

The face lists are:
[0, 1, 3, 7, 8, 9, 10, 11, 27, 31, 32, 33, 34, 35, 36, 40]
[2, 24, 25, 26, 28, 29, 30, 38, 39]
[4, 17, 18, 19, 20, 21, 22, 23, 41]
[5, 6, 12, 13, 14, 15, 16, 42, 43]
[37]


This corresponds with the indices, proof using index visualizer: