You don't need a list comprehension here -- `join` accepts any `iterable`: `'\n'.join(query['sql'] query in self.captured_queries)`