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
iren2701 [21]
3 years ago
6

Write a function called starts_with(prefix, wordlist) that takes as inputs a string prefix and a list of strings wordlist, and t

hat uses a list comprehension to return a list consisting of all words from wordlist that begin with prefix. For example:
>>> starts_with('fun', ['functions', 'are', 'really', 'fun!'])
result: ['functions', 'fun!']

>>> starts_with('on', ['only', 'functions', 'on', 'the', 'brain'])
result: ['only', 'on'] # note that 'functions' is *not* included

>>> names = ['Alex', 'Adlai', 'Alison', 'Amalia', 'Anbita']
>>> starts_with('A', names)
result: ['Alex', 'Adlai', 'Alison', 'Amalia', 'Anbita']

>>> starts_with('Al', names)
result: ['Alex', 'Alison']

>>> starts_with('D', names)
result: []
Hints:

Your list comprehension will need an if clause.

Make sure that you only include words that start with the specified prefix. For instance, in the second example above, the string 'functions' is not included in the return value, because the string 'on' is in the middle of 'functions', rather than at the start. As a result, you won’t be able to use the in operator to test for the presence of the prefix in a word.
Computers and Technology
1 answer:
Anvisha [2.4K]3 years ago
3 0

Answer:

Hi there! The question can easily be implemented by iterating through the array list an using the "startswith()" function of the String class. Please find explanation below.

Explanation:

We can write the code as below into a file called starts_with.py and run it from the command line. Sample input is also provided with results.

starts_with.py

import sys;

def starts_with(prefix, wordlist):

   for e in wordlist:

       if e.lower().startswith(prefix.lower()):

           starts_with_array.append(e);

starts_with_array = [];

prefix = input("Enter prefix: ");

wordlist = input("Enter word list: ");

wordlist = wordlist.split(',');

starts_with(prefix, wordlist);

print(starts_with_array);

Usage with Result

> starts_with.py

> Enter prefix: Fun

> Enter word list: Funtastic,Fun,Test,No

> ['Funtastic', 'Fun']

You might be interested in
When emergency changes have to be made to systems, the system software may have to be modified before changes to the requirement
goblinko [34]

Answer:

The Agile model

Explanation:

We can point out that this is all about the software development lifecycle model. In the software developmental lifecycle, the agile model is the most suited model that can be used to bring changes as per the requirement.

It is the model that provides huge flexibility as the changes can be made to the software even if the application is running. Moreover, this model follows documentation regarding the process of bringing the changes to the software. And even the new changes should pass the quality assurance test in order to go to the production phase.

What this does is that it actually ensures that your application is fit and is consistent to handle and perform operations.

5 0
3 years ago
After calling the customer service line of Delta airlines, Francis received an email asking her to fill out customer satisfactio
Irina-Kira [14]

Answer:

Surveys

Explanation:

Quantitative research methods seek to generate useful data to properly analyze the behaviors, opinions, and attitudes of some selected individuals. The collection method of quantitative methods includes all forms of surveys (paper, online, mobile, etc.).

The customer satisfaction questions are a form of surveys because they seek to discover her perception, attitude, and behavior towards their company.

3 0
4 years ago
Write a program that lists all ways people can line up for a photo (all permutations of a list of strings). The program will rea
irinina [24]

Answer:

Check the explanation

Explanation:

Executable Code:

def all_permutations(permList, nameList):

   # Define the function to create a list

   # of all the permutations.

   def createPermutationsList(nameList):

       # Compute and store the length of the list.

       n = len(nameList)

       # Return an empty list if the size is 0.

       if n == 0:

           return []

       # Return the element if the size is 1.

       if n == 1:

           return [nameList]

       # Create an empty list to store the permutations.

       permList = []

       # Start the loop to traverse the list.

       for i in range(n):

           # Store the first element of the current list.

           first = nameList[i]

           # Compute the store the remaining list.

           remaining = nameList[:i] + nameList[i+1:]

           # Start the loop and call the function recursively

           # with the remaining list.

           for perm in createPermutationsList(remaining):

               # Append the element in the permutation list.

               permList.append([first] + perm)

       # Return the permutation list.

       return permList

   # Call the function to compute the permutation list

   # and store the result.

   permList = createPermutationsList(nameList)

   # Start the loop to display the values.

   for perm in permList:

       for val in perm:

           print(val, end = " ")

       print()

# Call the main() function.

if __name__ == "__main__":

   # Prompt the user to enter the input.

   nameList = input().split(' ')

   permList = []

   # Call the function to create and output

   # the permutations of the list.

   all_permutations(permList, nameList)

#endcode

3 0
3 years ago
Which response best completes the following IF-ELSE statement?
nignag [31]
100 is the best guess I have sorry if it doesn’t help
5 0
2 years ago
What can help an interface user understand or navigate an online interface?​
Novosadov [1.4K]

Answer:

1. Add options and names.

2. Allow to provide back feedback.

3.Pay attention to patterns.

4.Stay consistent.

5.Use visual hierarchy.

Explanation:

5 0
3 years ago
Other questions:
  • Shirley was unsure about what career to go into. Her high school counselor suggested a personal assessment to point out Shirley’
    12·2 answers
  • "Simon Says" is a memory game where "Simon" outputs a sequence of 10 characters (R, G, B, Y) and the user must repeat the sequen
    5·2 answers
  • What is the difference between requirements and controls in the security process? Give examples of each.
    11·1 answer
  • Im new what are points
    6·2 answers
  • Which cable would you check if you can't access any web pages?
    12·1 answer
  • The "c" key and the "e" key are struck by
    12·2 answers
  • JQuery uses CSS selectors to select elements?
    5·1 answer
  • Testing a website includes visiting every web page on the site and selecting every link, tab, and button available.
    11·1 answer
  • Why is computer called information processing machine ?????​
    6·2 answers
  • Radio spectrum is the part of the complete range of electromagnetic waves that is used for radio communication from
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!