made an advanced solution in python