Make the function 1 operation shorter

Using list comprehensions to make the funkction shorter.