-7

I need to add blanks to an empty list as many as there are characters in the random word chosen from another list. How do I add blanks to the empty list so that later I can add letters to those blanks? The assignment wants 1. Make a list and choose a random word 2. Convert the word into list of characters 3. Print an empty list and add as many blanks as letters in the word 4. In a loop ask the user to enter a letter until they guess the word correctly or run out of chances 5. If the letter is correct add the letter to the correct index but in the blank list

Niva Ranavat
  • 1
  • 1
  • 2
  • 2
    This is not a good question. Show what you want your result to look like. The question is unclear. – joel goldstick Jul 26 '16 at 22:25
  • Possible duplicate of [Create an empty list in python with certain size](http://stackoverflow.com/questions/10712002/create-an-empty-list-in-python-with-certain-size) – Checkmate Jul 26 '16 at 22:28

3 Answers3

6
>>> word = "This-is-not-a-solve-my-problem-for-me-site"
>>> l = [None for char in word]
>>> l
[None, None, None, None, None, None, None, None, None,
 None, None, None, None, None, None, None, None, None,
 None, None, None, None, None, None, None, None, None,
 None, None, None, None, None, None, None, None, None,
 None, None, None, None, None, None]
Charles D Pantoga
  • 4,307
  • 1
  • 15
  • 14
0

If you want to initialize a list of length n, just do l = ['']*n

Alternatively, you can add items to the end of a list by:

l = [] #Initialize empty list
l.append(x) #Where x is the item you want to add

Finally, it's worth mentioning that you can google your problem or search stack overflow. I got Initialise a list to a specific length in Python and Create an empty list in python with certain size

Community
  • 1
  • 1
Checkmate
  • 1,074
  • 9
  • 16
0

Let me guess, perhaps you want to have somekind of Fill in the blanks thingy..

lets say variabe size has the length of the random word, then

my_list=['_']*size

if size is 10, then my_list has ['_', '_', '_', '_', '_', '_', '_', '_', '_', '_']

Sam Daniel
  • 1,800
  • 12
  • 22