how to print out the letters of the word with a certain pattern? ex. abcdef print a-6times, b-5 time, c-4 times, and the next letter again 6 times?

Question:

text='abcdef'
leng=len(text)
mylist=list(text)
def string():
    for i in range(leng-3):
        for j in range(leng-i):
            print(text[i],end='')
        print()
string()
#itrieddoingreversetoo 
#theoutputshouldbe:
'''
aaaaaa
bbbbb
cccc
dddddd
eeeee
ffff
each letter 6-5-4times in order
'''

how to print out the letters of the word with a certain pattern? ex. abcdef print a-6times, b-5 time, c-4 times, and the next letter again 6 times? I tried doing reverse too. how to print out the left def letters each 6-5-4 times in order?

Asked By: Jani Askarova

||

Answers:

You could use cycle from the itertools module to define a pattern and repeat it:

from itertools import cycle

freq_pattern = cycle([6, 5, 4])

for freq, letter in zip(freq_pattern, "abcdefg"):
    print(letter * freq)

Output:

aaaaaa
bbbbb
cccc
dddddd
eeeee
ffff
gggggg
Answered By: Tomer Ariel
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.