On Tue, 13 Jul 2010 14:33:09 -0400 Juan Marcelo Leiva Sandoval wrote: > def buscarIndice(nombre): > indice = 0 > for buscar in listaCalles: > if buscar.nombre == nombre: > break > else: > indice = indice + 1 > return indice
El hilo ha crecido mucho y es difícil de seguir, pero no parece que haya salido una solución con enumerate(), next() y generadores. En fin, mi idea era ésta (generalizo el atributo): def get_index(lst, attr, value): return next(idx for (idx, obj) in enumerate(lst) if getattr(obj, attr) == value) que podría llamarse así: index = get_index(lista_calles, "nombre", "nombre_de_una_calle") Pero repito, si la búsqueda por nombre de calles es habitual, lo que hay que hacer es usar diccionarios. _______________________________________________ Python-es mailing list Python-es@python.org http://mail.python.org/mailman/listinfo/python-es FAQ: http://python-es-faq.wikidot.com/