For example, I have a class Wall (doesnt have an init)
if a = Wall()
and str(a) outputs: '#'
if i have a string containing ‘####’
how can i turn that string into a list, that has the name of the class object like this:
[Wall(), Wall(), Wall(), Wall()]
>Solution :
You can use a list comprehension with a filtering clause:
walls = [Wall() for char in string
if char == '#']