subject

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.

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 21.06.2019 17:00
How can data be added to a new table in data base
Answers: 1
question
Computers and Technology, 21.06.2019 22:30
What are compression artifacts? 1) visible defects in the picture caused by the nature of the compression algorithm. 2) numbers that tell a web server how much to compress a picture for faster transmission. 3) invisible defects in the picture preserved by lossless compression. 4) numbers that tell a photo editing program how much to compress a picture for faster transmission.
Answers: 3
question
Computers and Technology, 22.06.2019 05:00
Which two editions of windows 7 support 64 bit cpus? choose two out of professional, business, starter, or home premium.
Answers: 1
question
Computers and Technology, 23.06.2019 02:00
As with any small island country, cuba has fewer natural resources than countries such as brazil. this affects their economy in that cuba a) exports only manufactured products. b) exports more products than it imports.. c) must import more products than it exports. d) has imposed trade barriers against the united states.
Answers: 3
You know the right answer?
Write a function called starts_with(prefix, wordlist) that takes as inputs a string prefix and a lis...
Questions
question
Mathematics, 05.03.2021 21:00
question
Mathematics, 05.03.2021 21:00
question
Arts, 05.03.2021 21:00
question
Mathematics, 05.03.2021 21:00
question
Mathematics, 05.03.2021 21:00
question
Mathematics, 05.03.2021 21:00
Questions on the website: 13722359