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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:44:06+00:00 2026-06-17T21:44:06+00:00

The format for this function is numLen(s,n): where s is a string and n

  • 0

The format for this function is numLen(s,n): where s is a string and n is an integer. What the code is supposed to do is return the number of words in the string that have length n, so:

numLen(“This is a test”, 4)

Would return 2, since two words have 4 characters.

def numLen(s, n):
'''
takes string s and integer n as parameters and returns the number of words
in the string s that have length n
'''
return s.split()
if len(s) == n:
    return 'hello'

I attempted to split the string into a list and check the length of each word in that list, but that didn’t seem to work out. The farthest I managed to get was returning “hello” when I replaced 4 with 14, just to see if the length code would work.

  • 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-17T21:44:07+00:00Added an answer on June 17, 2026 at 9:44 pm

    Try this:

    def numLen(s, n):
        return sum(1 for x in s.split() if len(x) == n)
    

    I’m using a generator expression, it works like this:

    • First, we split the string s in words using split()
    • Then, we filter those words that have exactly length n
    • We add 1 for each of those that meet the condition
    • And finally we add all the 1s
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some inherited JS code that uses this format: function main(param) { var
I have this function which is supposed to set a certain time format to
I have certain code that I want to optimize. It looks like this: function
I have this function. The visual studio profile marked the line with string.Format as
I have a class that takes a string in this format: 000067000000000012620060324b38e2cab3353 , encrypts
I have this function: void Log::Write(string logline){ //2011-10-12 13:07:40 correct format time_t rawtime; struct
I have a JavaScript function that returns a string. I want to write this
I have this function: public static string Join(this IEnumerable<string> strings, string separator) { return
This is the php code for date format on my web page function starkers_posted_on()
I have dialog created like this $('#add_error').click(function(e) { $('<div>') .load('/someaction/format/html/') .dialog({ title: 'Some title',

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.