Answered step by step
Verified Expert Solution
Question
1 Approved Answer
INSTRUCTIONS: Examine the starter code in the editor window, and run the code in the interpreter. The function extract _ even _ numbers _ in
INSTRUCTIONS:
Examine the starter code in the editor window, and run the code in the interpreter.
The function extractevennumbersinlist extracts the elements of a list that are even. The list myevens has been created by calling this function on mylist. Inspect the data in myevens.
Create a new list called myevens by using a list comprehension that does the same thing as extractevennumbersinlist, but all in one line.
The function extractdigitsfromstring extracts the characters in a string that are digits. In this function, the method string.isdigit is used to test whether or not a string is a digit or collection of digits The list strdigits has been created by calling this function on the supplied string s Inspect the data in strdigits.
Create a new list called strdigits by using a list comprehension that d
STARTER CODE:
mylist
def extractevennumbersinlistalist:
Returns a list of the numbers in the input alist
that are even numbers
NOTE: n if n is even, n if n is odd
result
for elem in alist:
if elem:
result.appendelem
return result
def extractdigitsfromstrings:
Returns a list of all the digits that appear in a string,
in the order in which they are encountered.
result
for c in s:
if cisdigit:
result.appendc
return result
def makedictofsquaresn:
Returns a dictionary that maps from integers to their squares,
starting with and ending at one less than the input n
result
for i in rangen:
resulti ii
return result
myevens extractevennumbersinlistmylist
s 'The answer is but many people guess
strdigits extractdigitsfromstrings
squares makedictofsquares
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