In Python sequences are iterable. Also a
A
str
is iterable.A
list
, tuple
, set
, dict
, ..., consumes iterables.greeting = "Hello World" print(list(greeting))
Output:['H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd']
So you can use this, to split the chars of a line, which represents the row (y coordinates).text = """ ******F**** *****W***** """.strip() # the text has a leading '\n' # and a tailing '\n' # strip removes whitespaces from left and right side of a str # also a newline is interpreted as whitespace. matrix2d = [list(line.strip()) for line in text.splitlines()] # iterate over lines, which are the rows # make a list from each row, which represents the columns # if you want to transpose the 2d matrix: matrix2d_transposed = list(zip(*matrix2d))
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
All humans together. We don't need politicians!