TripleAvian
TripleAvian

Reputation: 49

How to put a blank space in a list?

Example, I want to create this list:

a = [1, 2, 3, , 5]

How do I put in the blank space in between 3 and 5? I want to make a game of Hangman with it, and the blank space will be filled in by the player. The list itself will contain the Hangman question that the player will need to solve.

Upvotes: 0

Views: 11635

Answers (1)

jonrsharpe
jonrsharpe

Reputation: 121987

You can't leave an "empty space" in a list; each index has to contain something. In general, an "empty" index would be indicated by some sentinel value, often None.

For a game like Hangman, you will probably have your own empty space character, e.g. an underscore "_":

word = ["h", "e", "_", "_", "o"]

This allows you to easily print the word, showing the user where the blanks are:

>>> print " ".join(word)
h e _ _ o

Upvotes: 6

Related Questions