Question: mulDigits ( num , fn ) ( 1 pt ) Returns the multiplication of all digits in num for which fn returns True when receiving
mulDigitsnum fn pt
Returns the multiplication of all digits in num for which fn returns True when receiving the digits
as argument. You can assume that fn will always be a function that takes one number as argument
and returns a boolean value. You are not allowed to use lists, tuples, strings or convert num to
string using strnum
Examples:
isTwo lambda num: num # Simple anonymous function
mulDigits isTwo # Only evaluates to True
def divByFournum: # Conventional function definition
return not num
mulDigits divByFour # Only and evaluate to True
getCountx pt
Takes in a positive integer and returns a function that takes in an integer num, returning how many
times x appears as a digit in num. You are not allowed to use lists, tuples, strings or convert num
to string using strnum Note that num does not behave the same when num is negative,
returns while returns
Examples:
digit getCount
digit
getCount
DualIterator pts
An iterator that can iterate through all the elements of some sequence list string and when
reaching the end of the sequence, it loops back to the beginning. The iterator also includes the
method reverse that allows us to traverse in the reverse order, so when we reach the first element
of the sequence, it should loop to the last element of the iterable. You will need to initialize the
iterator settings in the constructor of the DualIterator class. You are not allowed to use any built
in reverse methods such as reverse:: etc.
The implementation of the iter method has been provided in the starter code. Do not modify
it You should only implement the following methods:
init method: iterator settings. Takes a sequence as argument. In lecture and
we presented examples of iterator implementations. Revise those examples so you can
determine any additional settings besides the sequence our solution uses only more
attributes
next: returns the next value. It does not raise a StopIteration exception since this is an
infinite iterator loops back
reverse: Takes no arguments and enables the change of direction in the iterator: from
forwards to backwards and vice versa
Examples:
it DualIterator
nextit
nextit
nextit
itreverse # it stopped at change direction
nextit
nextit
nextit
itreverse # it stopped at change direction
nextit
nextit
nextit
itreverse # it stopped at change direction
nextit
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
