Rhino 5 has a fast RhinoCommon method to do the search, no need to loop, eg:
scriptcontext.doc.Objects.FindByUserString(key, value, caseSensitive)
Note that Rhino 5 had a bug, it searches assignments made to the attributes OK, but not to the geometry. As long as you use the Rhino command _SetUserText _AttachTo=Attributes
or
rs.SetUserText(obj_id, key, value, attach_to_geometry=False)
method there is no problem.
_
c.