mirror of https://github.com/flaggo/pydu.git
add iter and iter.first, iter.last
This commit is contained in:
parent
f07f2dd24b
commit
5da517dbdb
|
@ -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
|
Loading…
Reference in New Issue