This is how I generally go about searching the values in a dict; my_key = next((key for key, value in dict.iteritems() if value == 'what im testing against'), None)
my_key will be None if the condition is never True. On Wednesday, 8 October 2014 15:14:40 UTC+1, [email protected] wrote: > > Hey Guys, > > I'll admit, dictionaries are not my strong point, and I could use a little > help ;) > > I'm looping through a dictionaries values, to find a particular value. If > it doesn't find the value, okay fine. But if it does find the value, I > need the key the value belongs to. > > #============================= > import pymel.core as pm > from itertools import chain > > sel = pm.ls(sl=1, fl=True) > > connectedVertGroups = {} > vertGroups = {} > for i, vtx in enumerate(sel): > > if vtx not in chain( *connectedVertGroups.values() ): > connectedVerts = [ vert for vert in vtx.connectedVertices() ] > connectedVerts.append(vtx) > connectedVertGroups["group_{0}".format(i)] = connectedVerts > vertGroups["group_{0}".format(i)] = vtx > > else: > ''' > TODO - Get the Key in connectedVertGroups that vtx belongs to, and > add connected verts to it if they're not already in it. verify it's also in > the correct vertGroup key. > ''' > connectedVerts = [ vert for vert in vtx.connectedVertices() if > vert not in connectedVertGroups.values() ] > #=========================== > > > Thx > Kev > > > -- You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/7d81e6db-334a-4457-9ba5-8a5be0facfbe%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
