You are viewing a single comment's thread. Return to all comments →
How does it keep looping and jumping to the next line? (Python2)
The entire argument to join is a list comprehension. Within the comprehension, for n in [int(raw_input())] for i in xrange(n) technically sets up a nested loop, although the outer loop only executes once.
for n in [int(raw_input())] for i in xrange(n)
[int(raw_input())] creates a list with one element, the height of the staircase. for n in [int(raw_input())] goes through (each of) the element(s) of that list, setting n to that element. (This only happens once because there is only one element). This part is just a trick to set n to the staircase height without needing a separate statement (separate line or semicolon).
for n in [int(raw_input())]
The inner loop, for i in xrange(n), is the real loop. Because it's the inner loop, n has already been set to the height of the staircase. Of course, this inner loop sets i to every integer from 0 to n-1, in turn.
for i in xrange(n)
('#' * (i + 1)).rjust(n) creates each line. For each iteration of the inner loop (and therefore for each value of n and i), the list of results has an element with (i + 1) '#' characters, right-justified in a field of width n.
('#' * (i + 1)).rjust(n)