Getting a glyph's index for the final file

I want to create a create convert to InDesign text tagged text based on @Tosche’s script. So far I need to create a dictionary with the glyph and index, but I’m not sure whether this is actually the correct way to get the glyph’s index for the final output:

glyphIndexDict = {}
for i,g in enumerate(Font.glyphs):
	if g.export:
		glyphIndexDict[] = i

Is it as simple as this or does it get reshuffled somehow in the end at export too?

The ‘.notdef’ glyph and the ‘space’ glyph (and ‘CR’ and ‘.null’ for TrueType if they are in the font) will be reorders to the beginning of the glyph list. Other than that there is no change.

edit: For CFF based fonts, only the ‘.notdef’ is reordered.