Double Iteration in List Comprehension
Suppose you have a text full of sentences and you want an array of words. # Without list comprehension list_of_words = [] for sentence in text: for word in sentence: list_of_words.append(word) return list_of_words I like to think of list comprehension as stretching code horizontally. Try breaking it up into: # List Comprehension [word for sentence … Read more