From 455dbe47fa2572cc12dbbb4c1d224db3aa5925f9 Mon Sep 17 00:00:00 2001 From: Til Boerner Date: Tue, 5 Feb 2019 20:08:10 +0100 Subject: [PATCH] Fix element skipping for empty iterators `next()` raises `StopIteration` when the iterator is empty. Providing a default returns that value instead, allowing to skip elements gracefully when you don't care if they exist. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b433f80..3146c2a 100644 --- a/README.md +++ b/README.md @@ -170,7 +170,7 @@ Iterator #### Skips first element: ```python -next() +next(, None) # default of `None` avoids exception for empty for element in : ... ```