diff --git a/pydu/iter.py b/pydu/iter.py new file mode 100644 index 0000000..d402a61 --- /dev/null +++ b/pydu/iter.py @@ -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