modified pn.py by using list comprehension