Re: "Find" in list of objects

2008-10-23 Thread bearophileHUGS
Andreas Müller: > is there a construct like > list.find (10, key='ID') Given the current Python a syntax like this is more probable: somelist.find(10, key=attrgetter('ID')) Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: "Find" in list of objects

2008-10-23 Thread Gabriel Genellina
En Thu, 23 Oct 2008 05:23:51 -0200, Andreas Müller <[EMAIL PROTECTED]> escribió: (Python 2.2.3 if this is relevant :-) I have a list of objects with, lets say, the attributes "ID", "x" and "y". Now I want to find the index of list element with ID=10. Of course I can loop through the list man

Re: "Find" in list of objects

2008-10-23 Thread bearophileHUGS
Andreas Müller: > is there a construct like > list.find (10, key='ID') You can create yourself a little convenience function, or you can use something like the following. First some testing code: class C: def __init__(self, id): self.id = id def __repr__(self): return "<%s