That works! Thank’s a lot spire2. 
I try to study each line to understand what each line of code is doing, so what I get is:
storing the name (string) ‘initialShadingGroup’ in the variable shading group
shadingGroup = ‘initialShadingGroup’
get all shapes connected to the ‘initialShadingGroup’ and store it in the variable allSgShapes
allSgShapes = set(cmds.listConnections(shadingGroup, type=‘shape’))
store the current selection in the variable userSelection
userSelection = set(cmds.ls(selection=True))
here I guess you get the difference between the current selection and the allSgShapes from the ‘initialShadingGroup’, which leaves us with the wanted selection (= lambert1 only within the selection)
userSgShapes = list(userSelection.intersection(allSgShapes))
select the userSgShapes
cmds.select(userSgShapes, r=True)
Is this approximately right? :curious: