sorted(iterable[, cmp[, key[, reverse]]])
In general, the key and reverse conversion processes are much faster than specifying an equivalent cmp function.
next(iterator[, default])
Retrieve the next item from the iterator by calling its next() method.
iter(o[, sentinel])
Return an iterator object. If the second argument, sentinel, is given, then o must be a callable object. The iterator created in this case will call o with no arguments for each call to its next() method; if the value returned is equal to sentinel, StopIteration will be raised, otherwise the value will be returned.
reduce(function, iterable[, initializer]) reduce just like reduce function in couchdb, it takes a list and returns a single value. reduce(lambda x, y: x+y, [1, 2, 3, 4, 5]) calculates ((((1+2)+3)+4)+5).
classmethod(function)
A class method receives the class as implicit first argument, just like an instance method receives the instance. To declare a class method, use this idiom:
123
classC:@classmethoddeff(cls,arg1,arg2,...):...
staticmethod(function)
A static method does not receive an implicit first argument. To declare a static method, use this idiom:
123
classC:@staticmethoddeff(arg1,arg2,...):...
property
12345678910111213141516171819
classC(object):def__init__(self):self._x=None# c.x will invoke this method@propertydefx(self):""I'm the 'x' property.""returnself._x# c.x = value will invoke this method@x.setterdefx(self,value):self._x=value# del c.x will invoke this method@x.deleterdefx(self):delself._x
Note This function is not normally available as a built-in since the name print is recognized as the print statement. To disable the statement and use the print() function, use this future statement at the top of your module.
Defining a view is done by creating a special document in a CouchDB database. The only real specialness is the _id of the document, which starts with _design/ —for example, _design/application. Other than that, it is just a regular CouchDB document.
Querying a View
/database/design/application/view/viewname
Map Function
A map function may call the built-in emit(key, value) function 0 to N times per document, creating a row in the map result per invocation.
(a map function can return any counts of emit(key, value) call)
Look up by key
To look something up quickly, regardless of the storage mechanism, an index is needed. An index is a data structure optimized for quick search and retrieval. CouchDB’s map result is stored in such an index, which happens to be a B+ tree.
(couchdb will generate a file with name xxxx.view to store the result of map/reduce function, it will copy the desired data from documents to the view file, not just reference it, so a view file may be very large)
total_rows: how many documents are there in this view result offset: position/index of this document/the first document in this view result
Aggregation Function
Reduce functions are similar to aggregate functions in SQL. They compute a value over multiple documents.
Reduce functions operate on the output of the map function (also called the map result or intermediate result ).
This reduce function takes two arguments: a list of keys and a list of values .
You’ll see one difference between the map and the reduce function. The map function uses emit() to create its result, whereas the reduce function returns a value.
Couchdb doesn’t have a keyword like distinct, but we can use group query parameter to group the result of reduce function, as we mentioned in last section, a reduce function only returns one value, but when we add group=true query parameter, multi values will be returned(each value is the reduce result of according group), grouped by the key in keys list, in this way, we can get the distinct keys(in this case, distinct tags)
Coucdb reduce result by default discard keys, so in the reduce result, key always be null, but if we add group=true in query, key will be used to grouping, so key will be reserved.
group=true parameter can only be used on a view which has reduce function.
if a view has a reduce function, by default a query will return the result of reduce. we can explicit pass reduce=false to get map result instead of reduce result.
我们知道在javascript中,对象跟数组都是构建在类似hashtable的数据结构上的, 即它们都是基于键值对的,所以在这一点上,我们可以把数组看成跟对象是一样的,对于一个javascript object, 我们使用 for (var prop in object)这种语法来遍历一个对象中的内容,这种方式对数组一样适用:
git remote add <remote-name> <remote-repo-url>
Add another remote for current git branch and name it with given name remote-name
git remote rename <original-name> <new-name>
Rename remote original-name to new-name
git config branch.<branch-name>.remote <remote-name>
Set the default remote of branch branch-name to remote-name, this command will generate below segment in .git/config:
git clean -fgit clean -f -d
Remove untracked file from working directory. If -d used, will remove untracked directories in addition to untracked files.
git add -p
Interactively choose hunks of patch between the index and the work tree and add them to the index. This gives the user a chance to review the difference before adding modified contents to the index.