Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö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µÄwiki ÁÐ×Ó.

#coding=utf-8
from newtest.wiki.models import WiKi
from django.template import loader, Context
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render_to_response

def index(request, pagename=""):
"""ÏÔʾÕý³£Ò³Ã棬¶ÔÒ³ÃæµÄÎÄ×Ö×öÌØÊâµÄÁ´½Ó´¦Àí"""
......

Python ¶¨Ê±ÔËÐнű¾

import sys
import os
import datetime
import time
class ArgsDealwith:
   
    def arg_environment(self, args):
        filepath = ('PYTHON_PATH', 'path')
        for i in filepath:
 &nbs ......

PythonÄÚ½¨º¯ÊýÖ®——filter,map,reduce

     ÔÚ½²Êöfilter£¬mapºÍreduce֮ǰ£¬Ê×ÏȽéÉÜÒ»ÏÂÄäÃûº¯Êýlambda¡£
     lambdaµÄʹÓ÷½·¨ÈçÏ£ºlambda [arg1[,arg2,arg3,...,argn]] : expression
     ÀýÈ磺
     >>> add = lambda x,y : x + y
>>> add ......

pythonѧϰ

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

pythonÁ½¸ödictÏà¼Ó


>>> a = {'1':'2'}
>>> b = {'3':'4'}
>>> a+b
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'dict' and 'dict'
>>> a.update(b)
>>> a
{'1': '2', '3': '4'} ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ