hackerrank solution for lists in python