Chapter 14.3.7. Working with Arrays

Python has a number of handy functions for working with lists that JavaScript doesn’t. MochiKit helps out with functions that work on “array-like” objects. The isArrayLike function returns true if the object has a typeof “object” and the object has a length property.

In Python, the map and filter functions have largely been replaced by list comprehensions, and there is talk of deprecating those functions at some point years in the future. JavaScript doesn’t offer list comprehensions yet, however. The map and filter functions can be amazingly useful and provide concise ways to do common operations with arrays. Here’s an example of these in use:

 >>> mylist = [1,2,3,4,5,6,7,8,9] [1, 2, 3, 4, 5, ...

Get Rapid Web Applications with TurboGears: Using Python to Create Ajax-Powered Sites now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.