Condensed the program with list comprehension.