Now that we have created our very first expressions in AngularJS, its time to make another step, this time with something much more interesting. We are going to connect an input field with an expression that will automatically display whatever we type in.
An "iterable" object in Python is one that we can iterate on it using a for loop. For example a list is "iterable" because we can iterate over its elements:
Here you'll find a few simple examples using AngularJS.
We have seen how to parse the HTML file and print the links using the HTMLParser module of Python, but instead of printing them to the screen we should somehow process the links.
That's what we are going to do now. We are going to extract the links and let some other code collect or process them.
The difference I've just encountered is that urllib will return the content of a page even if the page is not found (404) while urllib2 will throw an exception.
We saw how take a simple function and using callbacks make it more general. We also saw how to create an iterator to make our code more straight-forward. This time we are going to see how to convert the plain function into a generator that, after understanding how generators work, will seem to be the most obvious solution.
Earlier we saw how callbacks can be better than plain functions, but we have other possible solutions. We can also create a possibly unbounded iterator that will go over the elements of our series making our code look even more straight-forward than the solution with the callback.
What if you need to process a series of values to answer a certain question, that you cannot store in memory as a list? For example when you read a huge file? Or if you can calculate the next value based on some of the previous values and some external information that comes to light during processing. Even a random series. Or if the series is infinite and you don't know up-front how far you need to go to find your answer.
In this article we are going to see 2 solutions:
A Generator Expression is doing basically the same thing as a List Comprehension does, but the GE does it lazily. The difference is quite similar to the difference between range and xrange.
A List Comprehension, just like the plain range function, executes immediately and returns a list.
A Generator Expression, just like xrange returns and object that can be iterated over.