Computers and Technology

Write a function called starts_with(prefix, wordlist) that takes as inputs a string prefix and a list of strings wordlist, and that 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.

answer
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 10:40, Morghurley2000
"it security policy enforcement and monitoring" respond to the following: describe how monitoring worker activities can increase the security within organizations. describe the rationale that managers should use to determine the degree of monitoring that the organization should conduct. explain the extent to which you believe an organization has the right to monitor user actions and traffic. determine the actions organizations can take to mitigate the potential issues associated with monitoring user actions and traffic.
Answers: 3
image
Computers and Technology, 23.06.2019 12:00, lyn94
Using the list, you can select the number of photos that will appear on each slide. a. theme b. frame shape c. pictures in album d. picture layout
Answers: 1
image
Computers and Technology, 23.06.2019 20:00, shadow6728g
How much current flows through the alternator brushes? a. 2–5 a b. 25–35 a, depending on the vehicle c. 5–10 a d. 10–15 a
Answers: 2
image
Computers and Technology, 23.06.2019 21:30, jayybrain6337
Enzo’s balance sheet for the month of july is shown. enzo’s balance sheet (july 2013) assets liabilities cash $600 credit card $4,000 investments $500 student loan $2,500 house $120,000 mortgage $80,000 car $6,000 car loan $2,000 total $127,100 total $88,500 which expression finds enzo’s net worth?
Answers: 1
Do you know the correct answer?
Write a function called starts_with(prefix, wordlist) that takes as inputs a string prefix and a lis...

Questions in other subjects: