Pregunta de entrevista de Hitachi Rail

Two Python questions involving string and array manipulation.