Refactor List as string to use isinstance