Browse Source

Fix element skipping for empty iterators

`next(<iter>)` 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.
pull/14/head
Til Boerner 5 years ago
committed by GitHub
parent
commit
455dbe47fa
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 1 additions and 1 deletions
  1. 2
      README.md

2
README.md

@ -170,7 +170,7 @@ Iterator
#### Skips first element:
```python
next(<iter>)
next(<iter>, None) # default of `None` avoids exception for empty <iter>
for element in <iter>:
...
```

Loading…
Cancel
Save