Answered step by step
Verified Expert Solution
Question
1 Approved Answer
please write this code in python and start with def street_addresses(addresses): Part I: Validate Street Addresses (10 points) Write a function street.addresses), which takes a
please write this code in python and start with
def street_addresses(addresses):
Part I: Validate Street Addresses (10 points) Write a function street.addresses), which takes a single argument addresses, which is a list of strings The function analyzes each string, and, if the string's format matches the pattern of a valid street address as described below, the function appends the string's index in addresses into a returned list. A validly formatted address is defined by the following components, in the given order: 1. one or more digits 2. exactly one space 3. an uppercase letter, followed by any combination of uppercase letters, lowercase letters and spaces 4. exactly one space 5. the word ' Street', 'Road' or 'Path', capitalized exactly as given 6. optionally, the following text: a. exactly one space b. the string 'Apt.', capitalized exactly as given c. exactly one space d. exactly one uppercase letter Examples of validly formatted addresses are ' 58 Gnarled Oak Street' and ' 173 East Main Road Apt. Q Suppose the following list were passed as addresses ['21 Main Street', '12 Main Drive', '5 Elm Apt. E','6 Elm Path Apt. 5'1l The function would return [0, 3] because only the first and last strings in this example match the pattern defined above. Part I: Validate Street Addresses (10 points) Write a function street.addresses), which takes a single argument addresses, which is a list of strings The function analyzes each string, and, if the string's format matches the pattern of a valid street address as described below, the function appends the string's index in addresses into a returned list. A validly formatted address is defined by the following components, in the given order: 1. one or more digits 2. exactly one space 3. an uppercase letter, followed by any combination of uppercase letters, lowercase letters and spaces 4. exactly one space 5. the word ' Street', 'Road' or 'Path', capitalized exactly as given 6. optionally, the following text: a. exactly one space b. the string 'Apt.', capitalized exactly as given c. exactly one space d. exactly one uppercase letter Examples of validly formatted addresses are ' 58 Gnarled Oak Street' and ' 173 East Main Road Apt. Q Suppose the following list were passed as addresses ['21 Main Street', '12 Main Drive', '5 Elm Apt. E','6 Elm Path Apt. 5'1l The function would return [0, 3] because only the first and last strings in this example match the pattern defined above
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started