Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
beginner help in python
#1
Hi

I am trying to learn python and I am working with some problems in the book, I am trying to construct a function that reads the lines of a string input and prints out the words. I wish to remove the spacebars with a while loop. Here is the code for simply displaying the string:
def tokenize(lines):
    
    for line in lines:
        start = 0
        while start < len(line):
            print(line[start])
            start = start +1
    

tokenize(['apple  pie'])
-----------------------------------------------------------------------
And here is my attempt in trying to remove the spacebars with a while loop.

def tokenize(lines):
    
    for line in lines:
        start = 0
        while start < len(line):
            while line.isspace == False:
                print(line[start])
            start = start +1
    

tokenize(['apple  pie'])
Why doesn't my whileloop work? How do i change it so i don't have the spacebars in the final outprint?
snippsat write Dec-13-2020, 01:16 AM:
Added code tag in your post,look at BBCode on how to use.
Reply


Messages In This Thread
beginner help in python - by aghapouria - Dec-12-2020, 11:18 PM
RE: beginner help in python - by Larz60+ - Dec-13-2020, 02:03 AM
RE: beginner help in python - by bowlofred - Dec-13-2020, 07:08 AM
RE: beginner help in python - by aghapouria - Dec-13-2020, 03:26 PM
RE: beginner help in python - by ndc85430 - Dec-13-2020, 07:22 AM
RE: beginner help in python - by aghapouria - Dec-13-2020, 03:22 PM
RE: beginner help in python - by bowlofred - Dec-13-2020, 04:57 PM
RE: beginner help in python - by aghapouria - Dec-13-2020, 09:11 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020