I'll try to explain what is happening. Anyone who understands C++ or the API will probably be horrified by my explanation.
First we need to take a string, our object name, and use to create a Class of MDagObject. This is one of the most basic classes. Once we have a MDagObject, we can use it to create a MfnMesh Class, which is a class that has a lot of polygon specific functions.
The MfnMesh class has a function that will return the UV Shell ID of a UV coordinate. For example, the first and second polygons of a mesh are different shells, it would look like this:
0, 0, 0, 1, 1, 1
This is telling us that .map, .map, .map define a UV Shell and .map, .map, .map define a second shell.
If our mesh only had two triangles, this would point back to:
.vtx, .vtx, vtx belong to a UV Shell and .vtx, .vtx, vtx define a second UV Shell.
The Shell ID itself is not that useful to use, but it is useful as a grouping mechanism, since every UV coordinate in a shell will have the same ID. We can use this later in combination with the defaultdict.
So to get this list of shell IDs we have to deal with the API. The getUvShellIDs function doesn't return a value, it needs to be passed a variable to dump the results. If you have written shaders in HLSL or GLSL, its sort of like using inout.
We have to create ahead of time a variable to hold the results, but we have to create a very specific type of variable, to do that we use MScriptUtils. (This class is a crutch to cobble together python and API, and it still gives me headaches).
Now that we have the prerequisites, we can ask for the Shell IDs, this is an ordered list of the UV coordinates and which shell they belong to. If I use the Shell ID as a dictionary key, then I can iterate through the list of IDs and sort them into lists. This is where the defaultdict comes in handy. It eliminates the need to test if a key already exists buy assuming it does, as long as you tell the defaultdict what the default value is if the key doesn't already exist.
Since I know my mesh name and I know the value of i maps to a UV coordinate, I can use string formatting to setup my return value.