Regex And Parsing In Python Hackerrank Solution