converted for loops to single statements and list comprehension for SQL work