From cc5ff4e008a9c1eaf3027c25d2db9341d477be18 Mon Sep 17 00:00:00 2001 From: Michael Murtaugh Date: Tue, 14 Apr 2020 11:56:10 +0200 Subject: [PATCH] alternative way to make author_text --- simplelayout.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/simplelayout.py b/simplelayout.py index 8c3807a..ec885b2 100644 --- a/simplelayout.py +++ b/simplelayout.py @@ -36,6 +36,15 @@ for book in session.query(Book).all(): all_authors = [author.name for author in book.authors] glued_together = format_string.format(", ".join(all_authors)) + # ALTERNATIVE WAY... (without list comprehensions) + first = True + author_text = "" + for author in book.authors: + if not first: + text += ", " + author_text += "{}".format(author.name) + first = False + #if all_authors==['John Markoff']: # import ipdb; ipdb.set_trace()