I was trying to understand List Comprehensions because I needed to improve performance on my project.
I believe this is how they work but please correct me if I am wrong.
To convert a for loop into a list comprehension the below for loop -
for A in B:
if Condition:
List.append(A)
would turn into
E = [A for A in B if Condition]
I didn't realize this was a duplicate. If the answers on this post were unsatisfactory, you can see the other post at the top of this one.
I'm not sure if I understand what you asked correctly, but generally if you have a for loop like this :
It's equivalent list comprehension is :
If you have an else for your condition, it would be a little different. Consider the following example :
It would become like this :