You should change two lines. The first one is about PyQGIS 3, the other is about Python 3.
Change
QgsMapLayerRegistry.instance().mapLayers()
intoQgsProject.instance().mapLayers()
. Please check this answer out for more information.Change
layerMap.iteritems()
intolayerMap.items()
. Please check this postWhat is the difference between dict.items() and dict.iteritems()? and answers for additional information.