Home > OS >  What is Inline Iteration in Python?
What is Inline Iteration in Python?

Time:11-26

"What is Inline Iteration?" I tried googling this question but all the results are about List Comprehension. I thought it's the same thing until I read this comment:

"List comprehensions (not inline iteration) are indeed more optimized than..."

And the answer of this question:

"What you are using is called a list comprehension in Python, not an inline for-loop (even though it is similar to one)."

These people only mention that they are similar but never explain what the difference is. Are Inline Iteration and Inline For-Loop the same thing?

CodePudding user response:

From the comments in the Get difference from two lists in Python:

Pol: Someone told me that inline iteration is highly optimized as well...

orlp: List comprehensions (not inline iteration) are indeed more optimized than...

Here orlp is telling pol that was he calls "inline iteration" is correctly called a "list comprehension". "inline iteration" isn't a thing.


From the answer in Inline for loop

What you are using is called a list comprehension in Python, not an inline for-loop (even though it is similar to one)

I believe that this user is saying that a list comprehension is similar to a for loop. There is no such thing as an "inline for loop", but I see why someone would use that terminology when they don't know what it is called. Both of the questions you linked have answers that are clarifying the actual terminology we use in Python.

  • Related