Noté que Python2.6 agregó un siguiente() a list of global functions.¿Por qué Python 2.6 agregó una función global next()?
Retrieve the next item from the iterator by calling its next() method.
Si se da
default
, que se devuelve si se agota el iterador, de lo contrarioStopIteration
se eleva.
¿Cuál fue la motivación para agregar esto? ¿Qué puede hacer con next(iterator)
que no puede hacer con iterator.next()
y una cláusula except
para manejar StopIteration?
+1. La misma razón por la cual Python tiene una función len() incorporada. Consulte la respuesta aceptada a http://stackoverflow.com/questions/83983/why-isnt-the-len-function-inherited-by-dictionaries-and-lists-in-python para obtener el enlace al razonamiento de Guido. –
+1: Citar los documentos. –