Rewrote solution using list comprehension