Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8815687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:26:24+00:00 2026-06-14T04:26:24+00:00

Writing a hangman program in python and I’ve come across a problem when passing

  • 0

Writing a hangman program in python and I’ve come across a problem when passing in a file that has multi word strings and single word strings.

FILE:

hello brown fox

dog

cat

water

jump

#initialize list
wordList = []
# get and open file
getFile = raw_input("Enter file name: ")
filename = open(getFile, "r")

def readWords(filename):
    for line in filename:
        # split any multi word line
        line.split()
        # add line to wordList
        wordList.append(line)

Yet the out put for wordList still reads:

wordList = ['hello brown fox\n', 'dog\n', 'cat\n', 'water\n', 'jump\n']

I am trying to make it so that ‘hello brown fox’ appears as 3 separate strings.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T04:26:25+00:00Added an answer on June 14, 2026 at 4:26 am

    the problem you’re having is that you’re splitting but not saving the splitted line:

    >>> a = "hello brown fox"
    >>> a.split()
    ['hello', 'brown', 'fox']
    >>> a
    'hello brown fox'
    >>> 
    

    so:

    wordList.extend(line.split())
    

    should do the trick for you

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a python hangman program, and I wanted to be able to
I am writing a hangman game program in python and have run into a
Writing a python program, and I came up with this error while using the
Odd problem here. I'm writing a simple Hangman game in PHP, and while checking
Writing a program in which I need to split strings from a struct linked
Writing a recursive function, I want one fn that executes when the list has
Writing a simple program that will find exact duplicate files on my computer, but
I am writing a program that needs a list of English words as a
Writing a script that cds into another dir, loads the correct rvm rvmrc file,
writing a basic math program to help me understand python math calculation. if I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.