From 5da517dbdb5fc76d2a927189b40098c056a0cc6a Mon Sep 17 00:00:00 2001 From: Prodesire Date: Fri, 2 Feb 2018 23:55:53 +0800 Subject: [PATCH] add iter and iter.first, iter.last --- pydu/iter.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 pydu/iter.py 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