summaryrefslogtreecommitdiff
path: root/asciifarm/common
diff options
context:
space:
mode:
Diffstat (limited to 'asciifarm/common')
-rw-r--r--asciifarm/common/utils.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/asciifarm/common/utils.py b/asciifarm/common/utils.py
index b37ec02..cdc8dd5 100644
--- a/asciifarm/common/utils.py
+++ b/asciifarm/common/utils.py
@@ -38,3 +38,10 @@ def readFile(filepath):
with open(filepath, "r") as f:
text = f.read()
return text
+
+
+def get(collection, i, default=None):
+ """ Get an element in an indexed collection, or the default in case the index is out of bounds """
+ if i < 0 or i >= len(collection):
+ return default
+ return collection[i]