remove unsed global variable
use defined function
list comprehension
convert before checking
pep8