Dark theme

Doctests


How did you get on? Here's my attempt: test2.py.

Next, make the following changes to improve the code:

1) Download this file of emoticons into the same directory: emoticon.txt.

2) Change:
emoticons = (":D", ":)", ":/", ":p", ";)")
to
emoticons = get_emoticons()

3) Add the following function *above* remove_emoticons:
def get_emoticons():
    f = open('emoticons.txt', newline='')
    emoticons = f.read().split(",")
    return emoticons

Now it should read the emoticons from the file and run as before. Run the tests to see if the code still works.

So, the code now fails. Can you add a test for get_emoticons() that tests it returns what you expect it to? Note that when Python returns lists, strings in the lists have single quotes around them, and a comma *and* a space separating them.