Files
pplus-core/tests/snapshots/sync-mojo/tally.mojo
T
2026-10-05 03:03:38 +00:00

18 lines
516 B
Mojo

# Generated by Programming+ from pseudo. Not reviewed for Mojo best practices.
# How many times each base appears in T.
def tally_bases(t: String) raises -> Dict[String, Int]:
var tally = Dict[String, Int]()
var b: String
for i in range(t.count_codepoints()):
b = String(t[codepoint=i])
if b in tally:
tally[b] = tally[b] + 1
else:
tally[b] = 1 # first sighting of this base
return tally.copy()
def main() raises:
print(tally_bases("GATTACA"))