Python solution of strings and array part