Taking each month from a list of stocks and finding the average price.

Depends what level they're asking you to program at.

- If they want you to process it character-by-character, your approach is reasonable (but terrible otherwise).

- If they want you to process strings, it might be a good idea to use regex.

- If they want you to process the file itself, breaking apart each cell, use a library that already understands date formats, like `datetime`, and get that to convert them.

- If the real task is the core algorithm, rather than file loading, that's a CSV file - load it in with `pandas` and then deal with the resultant dataframe.

But frankly if you really want to extract the most value out of the task, do all four. You should know how to manage every level.

/r/learnpython Thread