Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

def find_first_starts_with(list, start_str): Given a list of strings, find the first string in the list that starts with start_str (case sensitive). Return value : the

def find_first_starts_with(list, start_str): Given a list of strings, find the first string in the list that starts with start_str (case sensitive).

Return value: the string meeting the criteria, or None if no strings meet this criteria

Assumptions:

o list will be a (possibly empty) list of strings (and only strings)

o start_str will be a string of at least length 1

Notes:

o As implied in the restrictions section of this document, you may not use startswith(), instead use the techniques you have been taught so far (hint: use slicing and len()).

Examples:

o find_first_starts_with(['ape','orange','apple'],'ap') 'ape'

o find_first_starts_with(['ape','orange','apple'],'app') 'apple'

o find_first_starts_with(['ape','orange','apple'],'o') 'orange'

o find_first_starts_with(['ape','orange','apple'],'A') None #no capital As

def find_all_starts_with(list, start_str): Given a list of strings, find all the strings that start with start_str and return them as a list (case sensitive, just like find_first_starts_with()).

Return value: a (possibly empty) list of all strings which meet the criteria

Assumptions & Notes:

o same as find_first_starts_with()

3

Examples:

o # find all strings starting with 'app' find_all_starts_with(['ape','orange','apple'],'app') ['apple']

o # find all strings starting with 'da' find_all_starts_with(['ape','date','data','dip'],'da') ['date','data']

o # find all strings starting with 'banana' find_all_starts_with(['apple','fred','rate'],'banana') []

python3 please

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Graph Databases

Authors: Ian Robinson, Jim Webber, Emil Eifrem

1st Edition

1449356265, 978-1449356262

More Books

Students also viewed these Databases questions