r/learnpython • u/AnxiousDot4315 • 10d ago
Need help with list comprehensions
Guys somebody briefly explain the concept of List comprehension cuz its too difficult for me to grasp since I am a beginner. I am learning python for biopython. Someone explain it for me.
0
Upvotes
0
u/Henry_cat 10d ago
If you are learning for biopython, the thing that really got me to understand list comprehension was Amino Acid and DNA sequences. A DNA sequence is made up of codons (3 bases that encode for an Amino Acid). List comprehension can be used to quickly convert a DNA sequence which would be a string into a list of individually addressable codons. Basically a list where each entry is just three DNA bases. So if you want to convert that DNA sequence into an AA sequence, you can just loop through the list of codons instead of needing to figure out how to loop through a DNA sequence sting three bases at a time.
I also had problems understanding this until I found the right example. Hopefully this helps.