summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Maw <richard.maw@codethink.co.uk>2015-05-06 11:14:13 +0000
committerRichard Maw <richard.maw@codethink.co.uk>2015-05-06 14:00:26 +0000
commit1651a358278d42506c7a8cbeed11b17d3ec283ee (patch)
treef44c6aab389b64d32d2e25bdc00c330495e5692d
parent534fe7aaca2d0e6048e92c6c76e455c5c972ad85 (diff)
downloadmorph-1651a358278d42506c7a8cbeed11b17d3ec283ee.tar.gz
morphlib.util: add word_join_list
This is useful for representing lists of items in status or exception messages.
-rw-r--r--morphlib/util.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/morphlib/util.py b/morphlib/util.py
index 70808cac..ab774dd5 100644
--- a/morphlib/util.py
+++ b/morphlib/util.py
@@ -692,3 +692,13 @@ def write_from_dict(filepath, d, validate=lambda x, y: True): #pragma: no cover
os.fchown(f.fileno(), 0, 0)
os.fchmod(f.fileno(), 0644)
+
+
+def word_join_list(l): # pragma: no cover
+ if len(l) == 0:
+ return ''
+ elif len(l) == 1:
+ return l[0]
+ else:
+ commasep = ', '.join(l[:-1])
+ return ' and '.join((commasep, l[-1]))