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
inessss [21]
3 years ago
12

The function below takes a single argument: data_list, a list containing a mix of strings and numbers. The function tries to use

the Filter pattern to filter the list in order to return a new list which contains only strings longer than five characters. The current implementation breaks when it encounters integers in the list. Fix it to return a properly filtered new list.student.py HNM 1 - Hef filter_only_certain_strings (data_list): new_list = [] for data in data_list: if type (data) == str and len(data) >= 5: new_list.append(data) return new_list Restore original file Save & Grade Save only
Computers and Technology
1 answer:
Nataliya [291]3 years ago
6 0

Answer:

Explanation:

The Python code that is provided in the question is correct just badly formatted. The snippet of code that states

return new_list

is badly indented and is being accidentally called inside the if statement. This is causing the function to end right after the first element on the list regardless of what type of data it is. In order for the code to work this line needs have the indentation removed so that it lines up with the for loop. like so... and you can see the correct output in the attached picture below.

def filter_only_certain_strings(data_list):

   new_list = []

   for data in data_list:

       if type(data) == str and len(data) >= 5:

           new_list.append(data)

   return new_list

You might be interested in
_______________ bytes of storage are needed to represent the name "sarah." two three five ten
Sholpan [36]
The answer is five...
4 0
3 years ago
Advertising managers work on websites used in __________?
Elena-2011 [213]
Campaigns

Hope this is right :-;
3 0
3 years ago
Read 2 more answers
Which tab do you select to change how you see your Word document on screen?
seraphim [82]

Answer:view

Explanation:i just took the test

8 0
3 years ago
Read 2 more answers
Which device allows your computer to talk to other computers over a telephone line as well as access the internet?
Sphinxa [80]

This question has 2 answers that I can see.

The first one would be a Dial Up Modem. These devices allow (or allowed, since they're pretty much obsolete) a computer to communicate over the phone lines and access the internet.

The second option for an answer would be a DSL Modem/Router. In a sense, a DSL (Standing for Digital Service Line) is a bit of a predecessor to traditional Dial Up, using a digital telephone line (However not the frequencies used for voice) to connect a computer or set of computers together and to the internet.

7 0
3 years ago
Assume that name is a variable of type String that has been assigned a value. Write an expression whose value is a String contai
Stella [2.4K]

Corrected (Modified) Question:

i. Assume that name is a variable of type String that has been assigned a value. Write an expression whose value is a String containing the last character of the value of name. So if the value of name were "Smith" the expression's value would be "h".

ii. Given a String variable named sentence that has been initialized, write an expression whose value is the number of characters in the String referred to by sentence.

Explanation of the corrected question

The whole question has been numbered (i) and (ii) just to separate or divide it into clearer sub questions.

Some parts of the question has also been removed since they are repetition of a part of the question.

Answer:

(i) name.charAt(name.length() - 1)

(ii) sentence.length()

Explanation:

No language  has been specified in the question for the code to be written in. However, I have chosen to write it in Java.

(i) In Java, to get a particular character in a string <em>str</em>, the function, charAt(x) is used, where x in the function represents the index of the character to be fetched. This is written as str.charAt(x).

In our case, x is the index of the last character in our string. To get the index of the last character in a string say <em>str</em>, the length of the string itself is used. However, indexing starts at zero. Therefore, to get the index, it will be the 1 subtracted from the length of the string as follows:

str.length() - 1

But note that, to get the length of a string, the method length() is used. For example if,

String str = "omobowale";

str.length() will return 9

Now to the question at hand, our string variable name is <em>name. </em>

Therefore to get its last character, we write:

<em>name.charAt(name.length() - 1)</em>

So if;

name = "Smith";

name.charAt(name.length() - 1) will return "h"

(ii) As explained in (i) above, to get the length (number of characters) of the variable string <em>sentence, </em>we simply write;

<em>sentence.length()</em>

<em>PS: The length of  a string is the number of characters present in the string.</em>

Hope this helps!

3 0
3 years ago
Other questions:
  • Pointers with classes a) A user-defined class named Timer has a constructor that takes two integer parameters to initialize hour
    14·1 answer
  • Software that interprets commands from the keyboard and mouse is also known as the A.hard drive.B.operating system.C.desktop or
    7·2 answers
  • Consider a simple application level protocol built on top of udp that allows a client to retrieve a file from a remote server re
    15·2 answers
  • Which part of the os provides users and applications with an interface to manipulate files?
    8·1 answer
  • Which area would a Gaming Designer fall under? Research and explain why you think so. Make sure to site your source and where yo
    7·1 answer
  • What does the noise reduction tool do?
    11·1 answer
  • Universal Containers sells its products online using a system built on Force Sites. The orders are captured and processed in Sal
    7·1 answer
  • Chris is working with other employees on a worksheet. The other employees have made comments, but they are not visible.
    11·1 answer
  • Can you see the processing step yes or no
    8·2 answers
  • Create a set of functions that compute the mean, median, and mode of a set of
    8·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!