April 4, 2008


Zen,大抵是西洋文音译“禅”字而来,什么是禅呢?
“言语道断,心行处灭”。必须要理解的东西是禅的不可理解,剩下的东西都是可以不理解的。当你理解了禅的不可理解性,那么就姑且算是入了一个门的吧。
我取的花名是“空山”,本意源于“空山新雨后”,然而细细品味竟然全不是一幅动态的竹喧浣女、莲动渔舟之意境。更多是一种随意世界的意味。这里我们发现中国的禅宗和其本源地印度的禅完全是很不一样的两个东西。
这点从两者修行的过程和目的上就明显的表现出来:Yoga是一种对肉体极限的挑战或者是压迫来达到心灵的静谧,而中国的禅则更多的有几分老庄的特点,主要采用Zazen的方式来游离精神。这种纯粹出于内省性的悟道方式和老庄的“坐忘”“心斋”“朝彻”并无本质上的区别
所以空山Empty mountain 也是一种放逐肉体而不是压制肉体,通过对内心的释放而参悟真谛的过程。“青青翠竹无非般若,郁郁黄花皆是妙谛。”人到禅时 则看什么都有禅味,大彻大悟的往往都是由平凡起而止于平凡的东西。奈何奈何奈若何,如此如此不过如此。禅道实际是一种幽默,一种玄机的幽默。生活总是有问题,并且总是很多问题。然后发现问题的人便叫有眼光,解决问题的人叫做有智慧。在我们学习的那么多的学科中能解决无限的问题的学科极少,CS不过是在一个充满了漏洞的空间上,用一种比较精确的方式去丑陋的模仿人的思维,Phsics则是从一种“我认为的”角度上看起来严密的推导一些基于既定的假设而得出的结论,Chemistry则从一种现象和无数遍重复的事件里去猜测结论,数学是唯一一门接近严密的,能真正处理无限的科学学科。而这种严密,这种禅味十足的精确,对于落后于精神无数年的现实科学而言都是过分奢侈的。
数学游离了科学的肉体,大彻大悟了一段禅道然后实而还是空山一段,最多取悦了参禅者的心灵。和无穷大和无穷小打交道,这种幸福的事情大抵只有禅家和数学家做的到。但这种自得其乐似的禅道怎么能解释给众生,才是大师该做的事情

—————————————-
以上只不过源于在读 Zen of Python 时候的一点遐想
最后附上 Python的禅(节选):

The Zen of Python

慢!
繁琐!
无接口!
没有自由!
不能贴代码!
莫名脚本错误!
风格越发校内化!
SNS不是抄袭抄袭!
还是wordpress好用!
ycool数据写成xml不标准!
备份的都是一些string流鸡肋!…

In this day, My plan is to understand how to build the normal Data Structure by Python.

Start Form List:

append( x)
extend( L)
insert( i, x)
remove( x)
pop( [i])
index( x)
count( x)
sort( )
reverse( )


we can use list as stack or queue very conveniently.

Is that all? Nope, there are some other build-in functions which are very usefull when used with lists: that is filter( ), map( ), reduce( ).

filter(function, sequence)” returns a sequence consisting of those items from the sequence for which function(item) is true. If sequence is a string or tuple, the result will be of the same type; otherwise, it is always a list.

Example:

>>> def f(x): return x % 2 != 0 and x % 3 != 0
...
>>> filter(f, range(2, 25))
[5, 7, 11, 13, 17, 19, 23]

map(function, sequence)” calls function(item) for each of the sequence’s items and returns a list of the return values. For example, to compute some cubes:


>>> def cube(x): return x*x*x
...
>>> map(cube, range(1, 11))
[1, 8, 27, 64, 125, 216, 343, 512, 729, 1000]

More than one sequence may be passed; the function must then have as many arguments as there are sequences and is called with the corresponding item from each sequence (or None if some sequence is shorter than another). For example:


>>> seq = range(8)
>>> def add(x, y): return x+y
...
>>> map(add, seq, seq)
[0, 2, 4, 6, 8, 10, 12, 14]

reduce(function, sequence)” returns a single value constructed by calling the binary function function on the first two items of the sequence, then on the result and the next item, and so on. For example, to compute the sum of the numbers 1 through 10:


>>> def add(x,y): return x+y
...
>>> reduce(add, range(1, 11))
55


If there’s only one item in the sequence, its value is returned; if the sequence is empty, an exception is raised.

LIST Comprehensions provides a more derect way to generate a list.

>>> [str(round(355/113.0, i)) for i in range(1,6)]
['3.1', '3.14', '3.142', '3.1416', '3.14159']

Use del L to delete a list or del L[index] to delete some elements of a list.


About Tuble

See some illustrations from Dive Into Python

A tuple is an immutable list. A tuple can not be changed in any way once it is created.

So what are tuples good for?

Note
Tuples can be converted into lists, and vice-versa. The built-in tuple function takes a list and returns a tuple with the same elements, and the list function takes a tuple and returns a list. In effect, tuple freezes a list, and list thaws a tuple.

Set:

Python also includes a data type for sets. A set is an unordered collection with no duplicate elements. Basic uses include membership testing and eliminating duplicate entries. Set objects also support mathematical operations like union, intersection, difference, and symmetric difference.


A set gonna be faster to execute member test. and what’s more two sets can + – | & ^ (letters in a or b but not both)

Dictionary:

The dictionary in Python is actruly the same as a hash table, like ” associative memories” or “associative arrays”.
The keys() method of a dictionary object returns a list of all the keys used in the dictionary, in arbitrary order (if you want it sorted, just apply the sort() method to the list of keys). To check whether a single key is in the dictionary, either use the dictionary’s has_key() method or the in keyword.

The dict() constructor builds dictionaries directly from lists of key-value pairs stored as tuples. When the pairs form a pattern, list comprehensions can compactly specify the key-value list.


Loop:


When looping through dictionaries, the key and corresponding value can be retrieved at the same time using the iteritems() method.


>>> knights = {'gallahad': 'the pure', 'robin': 'the brave'}
>>> for k, v in knights.iteritems():
...     print k, v
...
gallahad the pure
robin the brave

When looping through a sequence, the position index and corresponding value can be retrieved at the same time using the enumerate() function.



>>> for i, v in enumerate(['tic', 'tac', 'toe']):
...     print i, v
...
0 tic
1 tac
2 toe

To loop over two or more sequences at the same time, the entries can be paired with the zip() function.


>>> questions = ['name', 'quest', 'favorite color']
>>> answers = ['lancelot', 'the holy grail', 'blue']
>>> for q, a in zip(questions, answers):
...     print 'What is your %s?  It is %s.' % (q, a)
...
What is your name?  It is lancelot.
What is your quest?  It is the holy grail.
What is your favorite color?  It is blue.

To loop over a sequence in reverse, first specify the sequence in a forward direction and then call the reversed() function.


>>> for i in reversed(xrange(1,10,2)):
...     print i
...
9
7
5
3
1

To loop over a sequence in sorted order, use the sorted() function which returns a new sorted list while leaving the source unaltered.

>>> basket = ['apple', 'orange', 'apple', 'pear', 'orange', 'banana']
>>> for f in sorted(set(basket)):
...     print f
...
apple
banana
orange
pear


Tips about comparations

The Boolean operators and and or are so-called short-circuit operators: their arguments are evaluated from left to right, and evaluation stops as soon as the outcome is determined. For example, if A and C are true but B is false, A and B and C does not evaluate the expression C. When used as a general value and not as a Boolean, the return value of a short-circuit operator is the last evaluated argument.

Note that in Python, unlike C, assignment cannot occur inside expressions. C programmers may grumble about this, but it avoids a common class of problems encountered in C programs: typing = in an expression when == was intended.

too sequence can be compared with each other. like any dictionary.



Del.icio.us :