I don’t think it is clear here what “unused” means. Are you searching for meshes which are not deformed? This script would even find things which are connected to the initialShadingGroup. For example, if I make a polySphere and it has no history, no deformations or anything, it will not be deleted by your script, as it is.
In this script, you are iterating over meshes, but if you were to run this script over nurbsCurves, it would delete control icons from a rig. Are those nurbsCurves “unused” because they don’t have incoming connections? I would say no.
Also, a mesh is not a transform. The “transforms” variable name is a bit misleading.
Anyway. I think you’d better carefully define what you mean “unused” to mean, and do some more tests before you consider this the final solution. If it works in this particular instance for you, cool.
By the way, you can format code by enclosing it in triple backticks or a code block.
```
Code here
```