Simplified code by using a list comprehension

This is a minor change to simplify the code.