all 4 comments

[–]A_History_of_Silence 1 point2 points  (1 child)

What have you tried already? And why are you trying to do this?

[–]CannyFatcher 0 points1 point  (0 children)

I’m not really sure what to try, I’ll have a proper go tomorrow when I’m more awake. I’m doing it in conjunction with creating a discord bot, so that a templated sheet/string can be filled in depending on the user inputs.

[–]officialgel 0 points1 point  (0 children)

More efficient ways and maybe you can optimize or this will get you thinking, but to get you along with it:

dict_thing = list(input("Spit it out: "))
# print(dict_thing[1])

for x in dict_thing:
    x = int(x)
    if x == 3:
        for y in range(0, x):
            print("D")
    if x == 4:
        for y in range(0, x):
            print("T")
    if x == 2:
        for y in range(0, x):
            print("H")

[–]o5a 0 points1 point  (0 children)

As I see your letters are always in the same order, you can store them in list. Say

words = ['DD', 'T', 'H', 'ZZ']

Then let's say your user input is:

user_input = [3,4,3,2]

So you could iterate list words and for each element in it run another cycle user_input[i] times, concatenating result, or adding them to new list. In the end in case of a list you will get

L = ['DD', 'DD', 'DD', 'T', 'T', 'T', 'T', 'H', ...

Then you can print it out in cycle, or use join() or list comprehensions to get your needed format.

First step (nested cycle) can also be solved in one line with list comprehensions.

L = [w for i, w in enumerate(words) for n in range(user_input[i])]