Is there an easy way to comprehend the following
words = ["x", "mouse", "looloo", "google", "foo"]
terms = set()
for i in xrange(len(words)):
terms = terms.union([" ".join(words[j:j + len(words) - i]) for j in xrange(len(words))])
return sorted(terms, key=len, reverse=True)
You can put multiple loops in a list comprehension by listing them in the same order as you would when using nested for loops.
Something like:
But I find your algorithm rather hard to read as it is, so I am not even sure this will do what you want.