add iter and iter.first, iter.last

This commit is contained in:
Prodesire 2018-02-02 23:55:53 +08:00
parent f07f2dd24b
commit 5da517dbdb
1 changed files with 19 additions and 0 deletions

19
pydu/iter.py Normal file
View File

@ -0,0 +1,19 @@
"""iteration tools"""
def first(iterable):
"""
Get the first item in the iterable.
"""
return iter(iterable).next()
def last(iterable):
"""
Get the last item in the iterable.
Warnning, this can be slow.
"""
item = None
for item in iterable:
pass
return item