
But that was not the primary motivator for adding them to the language.
I don't think the original author thinks that way either about string comprehensions. I was asked about the kind of speed benefits that string comprehensions would have over using a generator with "".join() and I used f-strings as an example because the benefits would be similar. By the way now that i think about it, comprehensions would fit into f-string interpolation pretty nicely. f""" Guest list ({len(people)} people): {person.name + '\n' for person in people} """
Which massively reduces the possible kinds of comprehensions one might write, and I suspect most of those are already covered by string methods.
I actually replied to David Mertz about this. String comprehensions can derive substrings from any iterable. Just like the only requirement for using a generator expression in "".join() is that it produces strings. Comprehensions can also have nested loops which can come in handy at times. And of course this doesn't mean I'm going to advocate for using them with complex predicates.