Aren asked for “any number of resulting lists”, which I interpreted as him wanting one list of UVs per shell, whereas the sorted zip version returns a single list of ordered UVs with no way to figure out from which shell they belong to. But that wouldn't be the first time that I misunderstand something! :)
On 18 August 2016 at 11:41, Justin Israel <[email protected]> wrote: > > > On Thu, Aug 18, 2016 at 4:40 PM Justin Israel <[email protected]> > wrote: > >> On Thu, Aug 18, 2016 at 4:34 PM Christopher Crouzet < >> [email protected]> wrote: >> >>> If I'm understanding it right, try this: >>> >>> import itertools >>> >>> def sort_uvs_by_shells(uvs, shells): >>> groups = itertools.groupby(sorted(zip(shells, uvs)), key=lambda x: >>> x[0]) >>> return ((group[0], [x[1] for x in group[1]]) for group in groups) >>> # dictionary version: >>> # return {group[0]: [x[1] for x in group[1]] for group in groups} >>> >>> uvs = list(range(16)) >>> shells = [0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1] >>> result = sort_uvs_by_shells(uvs, shells) >>> for shell, uvs in result: >>> # dictionary version: >>> # for shell, uvs in result.iteritems(): >>> print("uvs for shell %d: %s" % (shell, uvs)) >>> >> >> Nice example. Could this even be shortened to something like this? (I >> have simplified the data for example purposes) >> >> from itertools import izip >> >> l1 = ['a', 'b', 'c'] >> l2 = [3, 2 ,1] >> print [i[1] for i in sorted(izip(l2, l1))]# ['c', 'b', 'a'] >> >> >> >> > Correction: Forget the use of itertool.izip. It is not necc here. > > [i[1] for i in sorted(zip(l2, l1))] > > > >> Justin >> >> >>> >>> On 18 August 2016 at 11:02, Aren Voorhees <[email protected]> wrote: >>> >>>> I realized that subject doesn't sound like it makes any sense - but >>>> here is what I'm trying to do: I am generating two lists...one looks >>>> something like this - >>>> >>>> [MeshUV(u'pCubeShape1.map[0]'), MeshUV(u'pCubeShape1.map[1]'), >>>> MeshUV(u'pCubeShape1.map[2]'), MeshUV(u'pCubeShape1.map[3]'), >>>> MeshUV(u'pCubeShape1.map[4]'), MeshUV(u'pCubeShape1.map[5]'), >>>> >>>> MeshUV(u'pCubeShape1.map[6]'), MeshUV(u'pCubeShape1.map[7]'), >>>> MeshUV(u'pCubeShape1.map[8]'), MeshUV(u'pCubeShape1.map[9]'), >>>> MeshUV(u'pCubeShape1.map[10]'), MeshUV(u'pCubeShape1.map[11]'), >>>> >>>> MeshUV(u'pCubeShape1.map[12]'), MeshUV(u'pCubeShape1.map[13]'), >>>> MeshUV(u'pCubeShape1.map[14]'), MeshUV(u'pCubeShape1.map[15]')] >>>> >>>> >>>> The other is something like this: [0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 0, 0, >>>> 0, 0, 0, 1] >>>> >>>> >>>> The two lists correspond to each other, so I'd like to sort the >>>> elements in the first list by the matching integer in the 2nd list. In >>>> this example there would only be two resulting lists of uvs, but ultimately >>>> there could be any number of resulting lists. >>>> >>>> >>>> BTW, the point of this is to sort the uvs of a given mesh into their >>>> different shells so I can perform an operation on all the shells of a mesh. >>>> >>>> >>>> >>>> Thanks! >>>> >>>> Aren >>>> >>>> -- >>>> 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/f2705166-dc4d-47b9-a3f0- >>>> 4272923fc084%40googlegroups.com >>>> <https://groups.google.com/d/msgid/python_inside_maya/f2705166-dc4d-47b9-a3f0-4272923fc084%40googlegroups.com?utm_medium=email&utm_source=footer> >>>> . >>>> For more options, visit https://groups.google.com/d/optout. >>>> >>> >>> >>> >>> -- >>> Christopher Crouzet >>> *http://christophercrouzet.com* <http://christophercrouzet.com> >>> >>> -- >>> 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/CANuKW51A%3D%3DaeKRa%2B9-nG% >>> 3Dwc8FrhgcccX-Rxf8YSKSnm-Lmvbdw%40mail.gmail.com >>> <https://groups.google.com/d/msgid/python_inside_maya/CANuKW51A%3D%3DaeKRa%2B9-nG%3Dwc8FrhgcccX-Rxf8YSKSnm-Lmvbdw%40mail.gmail.com?utm_medium=email&utm_source=footer> >>> . >>> For more options, visit https://groups.google.com/d/optout. >>> >> -- > 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/CAPGFgA0hA8TwVZ7n%3DxFH%3D- > kVmE-_-ucngSgTpEC7dxmWHA5ogA%40mail.gmail.com > <https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA0hA8TwVZ7n%3DxFH%3D-kVmE-_-ucngSgTpEC7dxmWHA5ogA%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > > For more options, visit https://groups.google.com/d/optout. > -- Christopher Crouzet *http://christophercrouzet.com* <http://christophercrouzet.com> -- 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/CANuKW52wkVhc78BDLWuTq06e%2B--iLVpHN0gs%2BjAa4wxZ7zwKMA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
