JPMorganChase Interview Question

Python - string based question