Question

IN PYTHON 3) Number of Words Write a function numWords() which takes in a string can...

IN PYTHON

3) Number of Words

Write a function numWords() which takes in a string can prints the number of words in the string. You can assume that words will only be separated with spaces, commas, and periods. "hello, world" -> 2 "this is cool" -> 3

4) Is Sorted

Write a function isSorted() which takes in an list of integers and returns true if the numbers are sorted from smallest to largest.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
import re
def numWords(s):
    return len(re.split(", .",s))

#=================================

def isSorted(lst):
    if(lst==None or len(lst)<=1):
        return True
    else:
        for i in range(1,len(lst)):
            if(lst[i] < lst[i-1]):
                return False
        return True

But I solved both for you.

Please upvote it

Add a comment
Know the answer?
Add Answer to:
IN PYTHON 3) Number of Words Write a function numWords() which takes in a string can...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT