Question
Write a generator expression that repeats each character in a given string 4 times. i.e. given gone, every time you call the next method on
Write a generator expression that repeats each character in a given string 4 times. i.e. given gone, every time you call the next method on the generator expression it will display gggg, then oooo, etc and instantiate it to an object called G. G = (..) # generatorExpression object Test and verify that iter(G) and G are the same things. What does this tell you about the nature of a Generator object/expression? Assign Iter(G) to an iterator object called it1 and advance it to the next element by using next method. Instantiate a new Iter(G) object called it2. Use the next method and advance it to the next element. Observe the result and compare it with the results of it1. Does the new Iter(G) object start the iterator from the start of the string object? Write down your understanding/conclusion from this experiment. How can you get back the Iter(G) to point back to the beginning of the string?
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