Computers and Technology, 26.02.2020 03:30 johniyabrown26
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.
Answers: 3
Computers and Technology, 22.06.2019 19:10
What a backup plan that you have created in a event you encounter a situation
Answers: 2
Computers and Technology, 23.06.2019 00:00
How do we use the sumif formula (when dealing with different formats) ?
Answers: 1
Computers and Technology, 23.06.2019 00:30
Write the html code to make a link out of the text “all about puppies”. it should link to a pdf called “puppies.pdf” inside the “documents” folder. the pdf should open in a new window.
Answers: 2
Write a function called starts_with(prefix, wordlist) that takes as inputs a string prefix and a lis...
Mathematics, 27.02.2020 03:56
Mathematics, 27.02.2020 03:56
Mathematics, 27.02.2020 03:56
Mathematics, 27.02.2020 03:56
Mathematics, 27.02.2020 03:56
Biology, 27.02.2020 03:57