Solves Problem 42 in Python and adds common function to read strings from file