Zhanylka
Zhanylka

Reputation: 15

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?

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?

Upvotes: 1

Views: 85

Answers (1)

Tomer Ariel
Tomer Ariel

Reputation: 1537

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

Upvotes: 1

Related Questions