Added advanced solution in Python