Python list comprehensions are by far the simplest and most readable loop expressions that I have worked with. Here’s an example where I have a list of lists of lists (corpus –> documents –> sentences) where I need to remove some items (called stop_words here) from the sentences.
1 2 3 4 5
Notice the array brackets added after each for expression so the program retains the same structure.
Another example, if I have to flatten such a deep list-
1 2 3 4