1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
luda_lava [24]
3 years ago
14

(count_word_lengths_test: 2 points). Write a function count_word_lengths(s) that, given a string consisting of words separated b

y spaces, returns a list containing the length of each word. Words will consist of lowercase alphabetic characters, and they may be separated by multiple consecutive spaces. If a string is empty or has no spaces, the function should return an empty list.
Computers and Technology
1 answer:
olga_2 [115]3 years ago
6 0

Answer:

The solution code is writing in Python.

  1. import re  
  2. def count_word_lengths(s):
  3.    processed_str = re.sub(' +', ' ', s)
  4.    
  5.    count = 0
  6.    word_list = processed_str.split(" ")
  7.    word_length_list = []
  8.    if(len(word_list) == 1):
  9.        return []
  10.    else:
  11.        for x in word_list:
  12.            word_length_list.append(len(x))
  13.    return word_length_list  
  14. print(count_word_lengths("i    have a dream"))

Explanation:

Since this program is expected to handle multiple consecutive spaces, we need to import Python regular expression module, <em>re </em>(Line 1). The usage of <em>re</em> is to use its<em> sub </em>method to substitute those multiple spaces with single space ' ' and assigned the modified string to variable <em>processed_str</em> (Line 4).

Next, use the string <em>split() </em>method to transform the processed_str into a list of individual words using single space " " as separator and assign the list to variable word_list (Line 7).

If the <em>word_list </em>contains only one word, this means the input string is either empty or no spaces and therefore it return empty list (Line 10). Otherwise, the program will proceed to a for loop that traverse through each word in the word_list and use len() method to get the length of the individual word and add the length value to the word_length_list (Line 13-14). At last, return the word_length_list as output (Line 16).

We can test the function using a sample string as in Line 19 and the output is [1, 4, 1, 5].

You might be interested in
2. Damaris is creating an object in Blender. He wants to change the illumination of the object that he is working on, but can’t
MariettaO [177]

The way that  Damaris can change the illumination of the object that he is working on in Blender is by:

  • First, one need to left-click on the lamp and then put  it in a place in your scene so that it can be able to illuminate the needed or required area. You can also do the above by  tweaking a lot of settings using the lamp options so that you can be able to get the lighting that you need . The most popular ones to tweak are those that have strength and color.

<h3>How do I change my light in Blender?</h3>

To view all options related to lights in Blender, enter the Object Data tab in the properties window while the lamp is still chosen.

You can alter your light kind and set energy and color settings at the top.

Therefore, The way that  Damaris can change the illumination of the object that he is working on in Blender is by:

  • First, one need to left-click on the lamp and then put  it in a place in your scene so that it can be able to illuminate the needed or required area. You can also do the above by  tweaking a lot of settings using the lamp options so that you can be able to get the lighting that you need . The most popular ones to tweak are those that have strength and color.

Learn more about Object from

brainly.com/question/2141363
#SPJ1

4 0
1 year ago
Write an SQL query for the HAPPY INSURANCE database that will, for each client of the agent named Amy, list the client's name an
matrenka [14]

The SQL Query for the HAPPY INSURANCE database given above is:

SELECT ClientName, AgentName FROM Client, Agent WHERE ClientAgent = AgentID and AgentName = 'Amy';

<h3>What is an SQL Query?</h3>

Structured Query Language (SQL) is a computer language that is used to manage relational databases and execute different operations on the data contained inside them.

This implies that the above code will only work where there is a database to manage.

Learn more about SQL at:
brainly.com/question/25694408
#SPJ1

4 0
2 years ago
Which of the following takes place during the research phase
LenKa [72]
I would say a formulation of the hypothesis
3 0
3 years ago
An examination of how well a particular solution is supportable given the organization’s current technological infrastructure an
san4es73 [151]

Answer:

Technical Feasibility is the correct answer of this question.

Explanation:

Examining how well a specific approach can be supported given the current technological infrastructure and resources of the company, including hardware, software, networking and personnel, is known as technical feasibility.

A technological feasibility report explores the specifics of how you plan to supply a goods or services to clients.It the strategic or operational strategy of where the company manufactures, sells, supplies and monitors its goods or services.

6 0
3 years ago
The dark side of communication involves interactions that are: Challenging; Difficult; Distressing; All of the above
Romashka [77]
When we engage in actions that are designed to sustain or preserve a relationship what is it called
6 0
4 years ago
Other questions:
  • How do you think your ability to work might be affected if you don’t magnify a document so that text is at a size for you to rea
    9·1 answer
  • When there is a limited amount of a product, such as rare art or collectible
    13·1 answer
  • (TCO G) _____ is when network managers deal with network breakdowns and immediate problems instead of performing tasks according
    7·1 answer
  • What is the Slide Sorter View used for?
    12·2 answers
  • What makes manually cleaning data challenging?
    15·1 answer
  • Write down the functions of network layer in your own words.ASAP
    14·1 answer
  • Choose a topic related to a career that interests you and think about how you would research that topic on the Internet. Set a t
    14·1 answer
  • 1. Microsoft Excel, MS Excel, or simply Excel is a______application by Microsoft Corporation. 2. Excel allows you to organize an
    13·1 answer
  • 6. Write a C++ program to print the largest three elements in an array. <br>​
    10·1 answer
  • What is output?<br> x = 2<br> y = 3<br> print (x * y + 2)<br> 4<br> 2<br> 8<br> 10
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!