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

  • SEARCH
  • Home
  • 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 8739367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:55:30+00:00 2026-06-13T10:55:30+00:00

learning python currently and having a bit of a problem. I’m trying to take

  • 0

learning python currently and having a bit of a problem. I’m trying to take a line from another subprogram and convert it into separate words that have been stripped of their punctuation besides a few. the output of this program is supposed to be the word and the line numbers it shows up on. Should look like this -> word: [1]

input file:

please. let! this3 work.
I: hope. it works
and don't shut up

Code:

    def createWordList(line):
        wordList2 =[]
        wordList1 = line.split()
        cleanWord = ""
        for word in wordList1: 
            if word != " ":
                for char in word:
                    if char in '!,.?":;0123456789':
                        char = ""
                    cleanWord += char
                    print(cleanWord," cleaned")
                wordList2.append(cleanWord)
         return wordList2

output:

anddon't:[3]
anddon'tshut:[3]
anddon'tshutup:[3]
ihope:[2]
ihopeit:[2]
ihopeitworks:[2]
pleaselet:[1]
pleaseletthis3:[1]
pleaseletthis3work:[1]

I’m unsure what this is caused by but I learned Ada and transitioning to python in a short period of time.

  • 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-13T10:55:32+00:00Added an answer on June 13, 2026 at 10:55 am

    You should set cleanWord back to an empty string at the top of each iteration of the outer loop:

    def createWordList(line):
        wordList2 =[]
        wordList1 = line.split()
        for word in wordList1:
            cleanWord = ""
            for char in word:
                if char in '!,.?":;0123456789':
                    char = ""
                cleanWord += char
            wordList2.append(cleanWord)
        return wordList2
    

    Note that I also removed the if word != " ", since after line.split() you will never have spaces.

    >>> createWordList('please. let! this3 work.')
    ['please', 'let', 'this', 'work']
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently learning Python using Zelle's Introductory text, and I'm trying to recreate one
I'm currently learning python and trying to do exercises at pyschools (if anyone knows
I'm currently learning on how to use the Python optparse module. I'm trying the
I'm currently trying to wrap my head around learning Python and I've come to
I'm currently learning python from a book called 'Python for the absolute beginner (third
I am currently learning Python from MIT OCW courses ? Anyone who have used
I'm currently going through the book Learning Python The Hard Way, and I'm trying
I'm currently learning Python and coming from a strong C# background. I keep hearing
I'm currently learning Python and I'm trying to make a small scraper but I'm
im currently learning python (in the very begining), so I still have some doubts

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.