curriculum/challenges/english/blocks/daily-coding-challenges-python/691f7773cddba1caf1bf5ece.md
Given a string representing the subject line of an email, determine how many times the email has been forwarded or replied to.
For simplicity, consider an email forwarded or replied to if the string contains any of the following markers (case-insensitive):
"fw:""fwd:""re:"Return the total number of occurrences of these markers.
email_chain_count("Re: Meeting Notes") should return 1.
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(email_chain_count("Re: Meeting Notes"), 1)`)
}})
email_chain_count("Meeting Notes") should return 0.
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(email_chain_count("Meeting Notes"), 0)`)
}})
email_chain_count("Re: re: RE: rE: Meeting Notes") should return 4.
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(email_chain_count("Re: re: RE: rE: Meeting Notes"), 4)`)
}})
email_chain_count("Re: Fwd: Re: Fw: Re: Meeting Notes") should return 5.
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(email_chain_count("Re: Fwd: Re: Fw: Re: Meeting Notes"), 5)`)
}})
email_chain_count("re:Ref:fw:re:review:FW:Re:fw:report:Re:FW:followup:re:summary:Fwd:Re:fw:NextStep:RE:FW:re:Project:Fwd:Re:fw:Notes:RE:re:Update:FWD:Re:fw:Summary") should return 23.
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(email_chain_count("re:Ref:fw:re:review:FW:Re:fw:report:Re:FW:followup:re:summary:Fwd:Re:fw:NextStep:RE:FW:re:Project:Fwd:Re:fw:Notes:RE:re:Update:FWD:Re:fw:Summary"), 23)`)
}})
def email_chain_count(subject):
return subject
def email_chain_count(subject):
markers = ["re:", "fwd:", "fw:"]
lower = subject.lower()
count = 0
for marker in markers:
start = 0
while True:
idx = lower.find(marker, start)
if idx == -1:
break
count += 1
start = idx + len(marker)
return count