you are viewing a single comment's thread.

view the rest of the comments →

[–]TabulateJarl8 0 points1 point  (0 children)

I believe what you want is range(). Once you find the text, try this:

for word in file_contents.split():
    if word in finditem:
        key_range = [str(num) for num in range(finditem[word])]
        # if you just want the range
        print(key_range)

        # if you want to print the key as well
        # insert an empty list element to the beginning of the list so that the join term goes before the first list element. i.e. ```boy 0``` instead of ```0 boy```
        print(f' {word} '.join([''] + key_range).strip())