Remove deprecated string module usage and replace with list comprehensions