Last answered:

23 Sept 2023

Posted on:

20 Jul 2023

0

Do you lose computational time when you put the iterable on the right counterintuitively like that?

Or its ideal in most situations?

2 answers ( 0 marked as helpful)
Instructor
Posted on:

21 Jul 2023

1

Hi Panagiotis!

Thanks for reaching out.


In many cases, list comprehensions can be more efficient and faster compared to traditional loops. However, it's important to note that the actual performance of list comprehensions depends on various factors, including the complexity of the expression and the size of the data. In some cases, using nested or complex expressions within list comprehensions can lead to decreased performance.

In general, for most straightforward and simple operations, list comprehensions offer an efficient and concise way to create lists in Python. However, for more complex or computation-heavy tasks, it's recommended to identify the most efficient solution for your specific use case. 


Hope this helps.

Best,

Ivan

Posted on:

23 Sept 2023

0

@Ivan Manov
 the video gives the direct opposite answer: that the list comprehensions "generally require more memory and run more slowly".

Though the video does not specify compared to what, is it safe to assume that to the nested loops?


Thus, which is true, in the end?

Submit an answer