Comprehensions let you express a filter-and-transform in one readable line instead of
a four-line loop, and idiomatic Python for data work leans on them heavily. Computing summary statistics
over a batch of sequences is exactly the shape of problem they were designed for, and learning to write
them well is the difference between code a collaborator can read and code they cannot.
Statement
You are given a set of DNA sequences.
Compute and print, each on its own line:
Count: <number of sequences>Total: <total bases across all sequences>Mean: <mean sequence length to two decimal places>Longest: <length of the longest sequence>GC-rich: <number of sequences with GC content strictly above 50 percent>
GC content is the fraction of G and C bases in a sequence.
Input — read from standard input
| Variable | Type | Description |
|---|---|---|
n
line 1
|
int |
The number of sequences
1 <= n <= 200
|
seqs
line 2..n+1
|
str |
One DNA sequence per line
1 <= len(seq) <= 1000, uppercase A, C, G, T only
|
These variables are already read for you in the starter code on the right.
Output
str five labelled statistic lines in the stated order
Sample Cases
3
ACGTACGT
GGGCCC
AAATTT
Count: 3
Total: 20
Mean: 6.67
Longest: 8
GC-rich: 1
1
GCGC
Count: 1
Total: 4
Mean: 4.00
Longest: 4
GC-rich: 1
Submit also runs your code against 3 hidden test cases. Hidden inputs are never shown — if one fails you'll get its number and a description of the mismatch, not the data.
Constraints
1 <= n <= 200- Labels must match exactly, with a single space after each colon
Meanis printed to exactly two decimal places- The GC-rich test is strictly greater than 0.5, so a sequence at exactly 50 percent does not count
Further Reading
[len(s) for s in seqs]gives you the lengths list that three of the five statistics need.sum(1 for s in seqs if gc(s) > 0.5)counts without building an intermediate list.- Compute GC as
(s.count('G') + s.count('C')) / len(s)— no rounding before the comparison.