I am taking a class to learn Morse code. At the beginning of the class, we are given a list of words in .txt format. I take this list and convert it to a Morse code .mp3 file. (LCWO.net) Each word is played once, however, it would be better to play it multiple times so I can learn the pattern.
My goal is to take the original text file and duplicate each word a number of times based on user input. I have been typing this manually, but reasoned that a computer could do it much easier. So, I chose Python to try and create the program. So far, I have figured out how to open the .txt file, create a list, strip out the newline character after each word, then print the list to the screen.
How can I loop through this list and create a copy of each word based on the user input? For example, a user would enter a '3' for 3 copies of each word. To illustrate, if the word list is ['cat', 'dog', 'chicken']
, how do I create a list that is: ['cat', 'cat', 'cat', 'dog', 'dog', 'dog', 'chicken','chicken', 'chicken']
, then write this list to a text file so each word is on one line?
filename is 'words.txt'
cat cat cat
dog dog dog
chicken chicken chicken
I think I can figure out how to get the user input and assign it to a variable, then use this variable as part of a loop for generating the new list. I also think I can figure out how to write the new list to a file. The part I need help with is figuring out how to create the list based on the input from the user (number of iterations for the word).
I realize that I'm asking for you to do the work, but I've read through the Python docs and I am struggling with a solution.
Thanks for your help!
Scott