The advantages of functional programming
A main feature of functional programming is the use of pure functions (functions that return the same output every time, for the same input). A simple example is the function sinx, which returns the same output for the same input, as opposed to the function today, which returns different values depending on when it is executed.
Another feature is that functions are first-class objects, i.e., they can be created dynamically and can be passed as arguments to, and even returned as values from, functions.
A key feature of functional programming is referential integrity, i.e., the lack of side effects. The execution of functions does not affect state, and hence eliminates deviation from the intended behaviour. This means that it is much easier to verify, parallelise and optimise programs, as well as write automated tools to perform the same tasks.
There are several theoretical and practical advantages of functional programming, which are beyond the scope of this article. Readers are encouraged to refer to the links provided.
Iterators are most commonly used in for Python, as shown below: for i in iter(alist):
print i
statements in
Another way of achieving the same is as follows: for i in alist:
print i
Calling iter() on a dictionary returns an iterator that loops over the keys: >>> monthlist={'jan' : 1, 'Feb' : 2, 'Mar' : 3, 'Apr' : 4, 'May' : 5, 'Jun' : 6, 'Jul' : 7, 'Aug' : 8, 'Sep' : 9, 'Oct' : 10, 'Nov' : 11, 'Dec' : 12} >>> for key in monthlist: