In order to enhance learning process I provide following explainer:
In expected output row number and position index for '\' are matching -> row[0]position[0], row[1]position[1]....row[4]position[4]. So the task is to have two iterators (one for row index and another for position index on row) and if they match put '\' into that position.
For better readability more descriptive names should have been used:
In expected output row number and position index for '\' are matching -> row[0]position[0], row[1]position[1]....row[4]position[4]. So the task is to have two iterators (one for row index and another for position index on row) and if they match put '\' into that position.
for i in range(start):
for loop to get row indices / number of rows to output -> 0, 1, 2, 3, 4for j, x in enumerate(range(1, start +1))
for loop to get position indices j (-> 0, 1, 2 , 3,4) and values x (-> 1, 2, 3, 4, 5) to output by using enumerate()'\\' if i == j else x
conditional expression to select what to yield - if row and position indices matches then '\' otherwise value*(...)
generator expression with unpacking generated values for rows -> row[0] \ 2 3 4 5, row[1] 1 \ 3 4 5..... row[4] 1 2 3 4 \ print(..., sep='')
printing generated and unpacked row values without separation.For better readability more descriptive names should have been used:
>>> start = 5 >>> for row in range(start): ... print(*('\\' if row == position else num for position, num in enumerate(range(1, start + 1))), sep='') ... \2345 1\345 12\45 123\5 1234\
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.