Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 16803

Converting For Loops To List Comprehensions [duplicate]

$
0
0

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.


Viewing all articles
Browse latest Browse all 16803

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>