Re: Sort a list of objects by an attribute of the objects

2008-07-08 Thread Ned Batchelder
This is a bit more complicated than you need. This will work: def sort_by_attr_inplace(seq, attr): import operator seq.sort(key=operator.attrgetter(attr)) --Ned. http://nedbatchelder.com joshuajonah wrote: > Resolved. > > Answer for those interested: > > def sort_by_

Re: Sort a list of objects by an attribute of the objects

2008-07-08 Thread joshuajonah
Resolved. Answer for those interested: def sort_by_attr(seq, attr): import operator intermed = map(None, map(getattr, seq, (attr,)*len(seq)), xrange(len(seq)), seq) intermed.sort() return map(operator.getitem, intermed, (-1,) * len(intermed

Sort a list of objects by an attribute of the objects

2008-07-08 Thread joshuajonah
Ok i have a list of form fields, i want to sort the list by the ".label" of the fields. I have tried a many different ways but i cant seem to make this work. I know this is more of a python question but this is the best resource I've found for these questions. Can anybody throw an example up for