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 8342639
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T05:49:51+00:00 2026-06-09T05:49:51+00:00

So, I already have the code to get all the words with digits in

  • 0

So, I already have the code to get all the words with digits in them out of the text, now all I need to do is to have the text all in one line.

with open("lolpa.txt") as f:
    for word in f.readline().split():
        digits = [c for c in word if c.isdigit()]
        if not digits:
            print(word)

The split makes the words all be in a different column.
If I take out the .split(), it types in the words without the digits, literally just takes the digits out of the words, and makes every letter to be in a different column.

EDIT: Yes, print(word,end=" ") works, thanks. But I also want the script to now read only one line. It can’t read anything that is on line 2 or 3 etc.

The second problem is that the script reads only the FIRST line. So if the input in the first line would be

i li4ke l0ke like p0tatoes potatoes
300 bla-bla-bla 00bla-bla-0211

the output would be

i like potatoes
  • 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-09T05:49:52+00:00Added an answer on June 9, 2026 at 5:49 am

    In Python v 3.x you’d use

    print(word, end='')
    

    to avoid the newline.

    in Python v 2.x

    print word,
    

    you’d use the comma at the end of the items you are printing. Note that unlike in v3 you’d get a single blank space between consecutive prints

    Note that print(word), won’t prevent a newline in v 3.x.

    —

    Update based on edit in original post re code problem:

    With input:

    i li4ke l0ke like p0tatoes potatoes
    300 bla-bla-bla 00bla-bla-0211
    

    this code:

    def hasDigit(w):
       for c in w:
          if c.isdigit():
             return True
       return False
    
    with open("data.txt") as f:
        for line in f:
            digits = [w for w in line.split() if not hasDigit(w)]
            if digits:
                print ' '.join(digits)
    #   break  # uncomment the "break" if you ONLY want to process the first line 
    

    will yield all the “words” that do not contain digits:

    i like potatoes
    bla-bla-bla    <-- this line won't show if the "break" is uncommented above
    

    Note:

    The post was a bit unclear if you wanted to process only the first line of the file, or if the problem was that your script only processed the first line. This solution can work either way depending on whether the break statement is commented out or not.

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

Sidebar

Related Questions

I already have code which lazy loads scripts on request. My issue now is
I have some code (which I cannot change) that I need to get working
I'm working on a video codec for OMAP3430. I already have code written in
I already have Java code to display and process data from a database. I
I have already have this code to force these URLs to HTTPS: RewriteCond %{HTTPS}
i have already finished code to passing data to url , and it did
This is my php code (I already have a connection to the db): $result
I have updated code for ActiveX functionality which already installed on client(in their Windows
I've have already implemented pagination using the following code: public Paginacao<Anuncio> consultarPaginado(int pagina, Integer
I have write this code but it does work only if I am already

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.