August 2018
Intermediate to advanced
248 pages
5h 51m
English
Let's see (in the rx_example2.py file) another way to write the code and obtain a similar result as in the first example.
We adopt the get_quotes() function in order to return an enumeration of the sequence, using Python's built-in enumerate() function, as follows:
def get_quotes(): import contextlib, io zen = io.StringIO() with contextlib.redirect_stdout(zen): import this quotes = zen.getvalue().split('\n')[1:] return enumerate(quotes)
We can call that function and store its result in a variable, zen_quotes:
zen_quotes = get_quotes()
We create the Observable using the special Observable.from_() function and chain operations such as filter() on the sequence, and finally use subscribe() to subscribe to the Observable.