Problem : Generator
acharbly at gmail.com
Fri Feb 15 02:55:23 EST 2019
How about this
Rever_gen = ( x*x for x in list1, reversed = True)
Rever_gen gets generator object and iterating it now gets reverse order..
Am I correct here? Suggest me
On Fri, 15 Feb 2019, 12:33 dieter <dieter at handshake.de wrote:
> Prahallad Achar <acharbly at gmail.com> writes:
> > How to implement reverse generator
> A generator generates a sequence of values.
> The notion "reverse generator" suggests that you have a sequence
> of values and want to produce it in reverse order.
> This is not always possible.
> def natural():
> i = 0
> while True: yield i; i += 1
> This generator generates all natural numbers (up to the memory limit).
> However, there is no "reverse generator" for the sequence of natural
> If you have a finate sequence of values, you can turn it into
> a list, reverse this list and iterate over it. This will give
> you a reverse generator for your sequence of values (though maybe
> an inefficient one).
More information about the Python-list