Ad
  • Default User Avatar

    The point of the for loop is to create the next row of the triangle by comparing every two adjacent characters.
    The next row is stored in the variable reduced. In the 4th line two consecutive characters are compared, and if
    they are the same, that character is added to reduced. If they are different, both are removed form the string 'RGB',
    and the remaining character is added to reduced. Let's say row[i] = 'R' and row[i+1] = 'B'. First, 'RGB'.replace(row[i], '')
    will return 'GB'. The second replace method will be called on 'GB'. It will replace 'B' with nothing and return 'G'.