Suppose you're a bioinformaticist and you have a gapped multiple sequence alignment (that is, a bunch of similar protein sequences, with dots and dashes inserted to line them all up), and you want the unaligned sequences, i.e., without all those dots and dashes. (Suppose further that you're using Bio.AlignIO from BioPython, and thus your multiple sequence alignment is an object containing other objects.)
You could write some loops and use .replace() a lot, or you could do something like this:
[''.join([x.upper() for x in record.seq if x.isalpha()]) for record in inputAlignment.get_all_seqs()]
(I'm really not sure how to describe the feeling of satisfaction I get from replacing ~20 lines of code with a list comprehension like this, but it's definitely rewarding.)
You could write some loops and use .replace() a lot, or you could do something like this:
[''.join([x.upper() for x in record.seq if x.isalpha()]) for record in inputAlignment.get_all_seqs()]
(I'm really not sure how to describe the feeling of satisfaction I get from replacing ~20 lines of code with a list comprehension like this, but it's definitely rewarding.)