Alphabet Rangoli

  • + 29 comments

    I won't lie, it took me over a week thinking about it, trying different things. Finally I came up with a good and clear solution. I am not sure if there is a more efficient way than this, comments always welcome.

    def print_rangoli(size):
        myStr = 'abcdefghijklmnopqrstuvwxyz'[0:size]
        
        for i in range(size-1, -size, -1):
            x = abs(i)
            if x >= 0:
                line = myStr[size:x:-1]+myStr[x:size]
                print ("--"*x+ '-'.join(line)+"--"*x)