Make the function shorter

Make function 2 times shorter using python list comprehensions.