įlask app with Apache WSGI on Ubuntu14/CentOS7. Removing Cloud Files - Rackspace API with curl and subprocessĬhecking if a process is running/hanging and stop/run a scheduled task on WindowsĪpache Spark 1.3 with PySpark (Spark Python API) Shellīottle 0.12.7 - Fast and simple WSGI-micro framework for small web-applications. Scheduled stopping and starting an AWS instanceĬloudera CDH5 - Scheduled stopping and starting services Uploading a big file to AWS S3 using boto module Simple tool - Google page ranking by keywords Python Unit Test - TDD using unittest.TestCase class Image processing with Python image library Pillow Python Network Programming IV - Asynchronous Request Handling : ThreadingMixIn and ForkingMixIn Python Network Programming III - Echo Server using socketserver network framework Python Network Programming II - Chat Server / Client Python Network Programming I - Basic Server / Client : B File Transfer
Python Network Programming I - Basic Server / Client : A Basics REST API : Http Requests for Humans with Flask Web scraping with Selenium for checking domain availability Python HTTP Web Services - urllib, httplib2 MongoDB with PyMongo I - Installing MongoDB. Connecting to DB, create/drop table, and insert data into a table Priority queue and heap queue data structure Python Object Serialization - yaml and json Python Object Serialization - pickle and json
Sets (union/intersection) and itertools - Jaccard coefficient and shingling to check plagiarismĬlasses and Instances (_init_, _call_, etc.)īits, bytes, bitstring, and constBitStream Strings - Escape Sequence, Raw String, and Slicingįormatting Strings - expressions and method calls Object Types - Numbers, Strings, and None Running Python Programs (os, sys, import) Here is an equivalent version which is much more verbose: The expression permutes even numbers from 0 through 4 with odd numbers from 0 through 4. Here is a much more complicated list comprehension example: Though list comprehensions construct lists, they can iterate over any sequence: When for loop are nested within a list comprehension, they work like equivalent for loop statement:
We can code any number of nested for loop in a list comprehension, and each may have an optional associated if test. > list( map((lambda x: x ** 2), filter((lambda x: x % 2= 0),range(10))) )Īctually, list comprehensions are more general. We have to combine filter with map iteration: The equivalent map requires a lot more work. The expression on the left computes the squares. The for loop skips numbers which the if on the right is false. We collect the squares of the even numbers from 0 to 9. But we can combine an if and a map, in a single expression: The filter call here is not much longer that the list comprehension either. > list(filter((lambda x: x % 2 = 0), range(10)))Īll of these use the modulus operator %, to extract even numbers. If we use if with list compression, it is almost equivalent to the filter built-in. For more advance kinds of expressions, however, list comprehensions will often require considerably less typing.
It's only a little bit longer that the list comprehension. If we had to use map, we would need to write a function to implement the square operation, probably, lambda instead of using a def: List comprehensions become more convenient when we need to apply an arbitrary expression to a sequence: The effect is similar to that of the for loop and the map call. List comprehensions collect the result of applying an arbitrary expression to a sequence and return them in a new list. While map maps a function over a sequence, list comprehensions map an expression over a sequence: > result = list(map(ord,'Dostoyevsky'))īut, we can get the similar result from a list comprehension expression. If we use map, we can get the same result with a single function call: If we want to collect the ASCII codes of all characters in a string, the most straightforward method is using a for loop and append the results to a list: Python's built-in ord returns the ASCII integer code of a character: