Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

ת£ºPythonµÄsort()

֮ǰѧϰµÚ¾ÅÕµÄÅÅÐòС½áµÄʱºò£¬¶Ôsort()ÅÅÐò·½·¨²»Àí½â£¬ÒòΪÀ¨ºÅÀïÃæ´øÁË×Ô¶¨ÒåµÄ±È½Ïº¯Êý¡£
ºóÀ´²éÊֲᣬ²Å·¢ÏÖsort()ÀïÃæ±¾À´¾Í´øÁËÕâÑùµÄ²ÎÊý¡£Äܹ»×Ô¶¨Òå±È½Ï·½·¨£¬È·ÊµºÜÁé»î¡£
²»½öÈç´Ë£¬ÔÚÍøÉϲ鵽һ¸ö²©¿Í£¬×÷Õß²»µ¥Í£ÁôÔÚÕâ±íÃæ£¬»¹²é¾¿ÁËsort()µÄÅÅÐòËã·¨£¬È·ÊµÓÐÒâ˼¡£
È«Îij­Â¼ÈçÏ£º
http://blog.donews.com/maverick/archive/2006/07/09/951101.aspx
ѧϰ±Ê¼Ç£ºPythonµÄÅÅÐò
PythonÓïÑÔÄÚÖÃÁËsort·½·¨£¬¿ÉÒԺܷ½±ãµØ¶Ôij¸öList½øÐÐÅÅÐò£º
L = [6, 5, 1, 3, 4, 2]
L.sort()
print L
---------- Run Python Program ----------
[1, 2, 3, 4, 5, 6]
ijЩʱºò£¬ÎÒÃÇÏ£Íû°´ÕÕ×Ô¼º¶¨ÒåµÄÅÅÐò¹æÔòÀ´ÅÅÐò£¨ÀýÈ磬°´¹Ø¼ü´ÊµÄÈ¨ÖØÅÅÐò£¬°´È˵ÄÄêÁäÅÅÐò£¬µÈµÈ£©¡£ÔÚJavaÓïÑÔÖУ¬ÎÒÃÇ¿ÉÒÔ×Ô¶¨ÒåComparatorÀ´ÊµÏÖ£¬PythonÖÐÒ²ÌṩÁËÀàËÆµÄ°ì·¨¡£
ÈôListÖÐÿ¸öÔªËØ¶¼ÊÇ2-tuple£¬tupleÖеÚÒ»¸öÔªËØÎªStringÀàÐ͵Äkeyword£¬µÚ¶þ¸öÔªËØÎª¸Ã×Ö·û´®¶ÔÓ¦µÄÈ¨ÖØ£¨intÀàÐÍ£©£¬Ï£Íû°´ÕÕÈ¨ÖØÅÅÐò£¨´Ó¸ßµ½µÍ£©£¬Ôò¿ÉÒÔÕâÑù£º
def my_cmp(E1, E2):
    return -cmp(E1[1], E2[1])    #compare weight of each 2-tuple
                    #return the negative result of built-in cmp function
                    #thus we get the descend order
L = [('a', 0), ('b', 1), ('c', 2), ('d', 3)]
L.sort(my_cmp)
print L
---------- Run Python Program ----------
[('d', 3), ('c', 2), ('b', 1), ('a', 0)]
ÕýÒòΪ¿ÉÒÔ×Ô¶¨Òåcmp·½·¨£¬ÎÒÃDz»·Á̽¾¿Ò»Ï£¬built-inµÄsort·½·¨£¬µ½µ×ÊDzÉÓõÄÄÄÒ»ÖÖÅÅÐòËã·¨£º
from random import shuffle
def my_cmp(E1, E2):
    print 'E1:', E1, 'E2:', E2
    return cmp(E1, E2)
L = range(0, 10)
shuffle(L)
print L
L.sort(my_cmp)
---------- Run Python Program ----------
[5, 3, 7, 6, 2, 8, 9, 4, 1, 0]
E1: 3 E2: 5
E1: 7 E2: 3
E1: 7 E2: 5
E1: 6 E2: 5
E1: 6 E2: 7
E1: 2 E2: 6
E1: 2 E2: 5
E1: 2 E2: 3
E1: 8 E2: 5
E1: 8 E2: 7
E1: 9 E2: 6
E1: 9 E2: 8
E1: 4 E2: 6
E1: 4 E2: 3
E1: 4 E2: 5
E1: 1 E2: 6
E1: 1 E2: 4
E1: 1 E


Ïà¹ØÎĵµ£º

pythonÖеÄÁбíÅÅÐò²Ù×÷

 
 
 
Python lists have a built-in sort() method that modifies the list in-place and a sorted() built-in function that builds a new sorted list from an iterable.
There are many ways to use them to sort data and there doesn't appear to be a single, central place in the various man ......

Python Socket ±à³Ì

client:
import socket, sys
if __name__ == '__main__':
    #´¦Àí²ÎÊý
    argv = sys.argv
    if (len(argv)!=3) or (len(argv)==2 and argv[1]=='/?'):
        print '>>>Useage:', argv[0], '<address> < ......

pythonѧϰ

     ÔÚpythonÖУ¬ÈκÎÊý¾ÝÀàÐͶ¼ÊÇ“¶ÔÏ󔣬°üÀ¨pythonÌṩµÄÄÚÖöÔÏó£¬Ò²°üÀ¨Óû§Í¨¹ýpythonÓïÑÔ»òÕßCÀ©Õ¹¿â´´½¨µÄ¶ÔÏó¡£
     pythonµÄ¶ÔÏóÊǶ¯Ì¬ÀàÐÍ£¬¶øÇÒÊÇÇ¿ÀàÐÍ£¬ÕâÒâζ×ÅÖ»ÓÐÀàÐÍÆ¥ÅäµÄʱºò²ÅÄܽøÐÐÏàÓ¦µÄ²Ù×÷¡£ÏÖÔÚ£¬ÎÒÃÇÀ´Ñ§Ï°pythonµÄÄÚÖöÔÏó£¬pythonµÄÄ ......

gentooÐ¶ÔØPythonµ¼ÖÂemerge²»ÄÜʹÓýâ¾ö·½·¨

½ñÌìÒ»²»Ð¡ÐİÑPython¸øÐ¶ÔصôÁË£¬µ¼ÖÂemerge²»ÄÜʹÓã¬×îÖÕÕÒµ½ÈçϽâ¾ö·½°¸£º
wget http://www.python.org/ftp/python/2.4.4/Python-2.4.4.tar.bz2\
tar xjvf Python-2.4.4.tar.bz
cd Python-2.4.4
./configure –with-fpectl –infodir=/usr/share/info/ –mandir=/usr/share/man
make
make instal ......

python½Å±¾Ä£Äâä¯ÀÀÆ÷

£¨Å¼¶û¿´µ½£¬ÅÂÍüÁË£©
·ÂÓû§´ò¿ªä¯ÀÀÆ÷È»ºóµã»÷µÈÐÐΪȻºó»ñÈ¡½á¹û£¬ÒÔÏÂÊÇÎÒʹÓùýµÄ·½·¨Ö»ÊÇÒÀÀµÓëie²»¹ýfirefoxµÈÓ¦¸ÃÒ²ÓÐÏàÓ¦µÄµ÷Ó÷½·¨£º
˼·¾ÍÊǵ÷ÓÃieµÄcom×é¼þÈ»ºó¾ÍÊǶÔdomµÄ²Ù×÷¸úÓÃjavascript²Ù×÷domÀàËÆ£¬Ê¾·¶´úÂëÈçÏÂ
#ÌìÑĵǽµØÖ·
tianyalogin = "http://www.tianya.cn/"
tianya_user = "xxxxx" ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ