With the coming nightly version you can keep the FESpace-elements in a list, and obtain dof numbers from them.
I am completely in favour of Lukas' O(N) algorithm (instead of the original O(N^2) method). With the nightly fixes, you can store numbers, element-ids, or FESpace-elements in the list.
Joachim