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

pythonË㷨ʵ¼ù6 ¶ÑÅÅÐò

#¶ÑÅÅÐò
def Heapify(mylist, start, end):
left = 0
right = 0
maxv = 0
left = start * 2
right = start * 2 + 1
while left <= end:
maxv = left
if right <= end:
if mylist[left] < mylist[right]:
maxv = right
else:
maxv = left
if mylist[start] < mylist[maxv]:
tmp = mylist[maxv]
mylist[maxv] = mylist[start]
mylist[start] = tmp
start = maxv
else:
break
left = start * 2
right = start * 2 + 1

def BuildHeap(mylist):
size = len(mylist)
i = (size -1) // 2;
while i >= 0:
Heapify(mylist, i, size - 1)
i = i - 1

def HeapSort(mylist):
BuildHeap(mylist)
i = len(mylist) - 1

while i >= 0:
tmp = mylist[0]
mylist[0] = mylist[i]
mylist[i] = tmp

Heapify(mylist, 0, i - 1)
i = i - 1

mylist0 = [11, 23, 1, 24, 112, 200, 9, 32]
HeapSort(mylist0)
print(mylist0)


Ïà¹ØÎĵµ£º

Python MySqlDB Ôöɾ¸ÄÊý¾Ý¿â


ÏÂÔØ°²×°MySQLdb
http://sourceforge.net/projects/mysql-python/ ºÃÏñû¿´µ½windows°æ±¾for python2.6µÄÏÂÔØ£¬ÍøÉÏËÑË÷µ½Ò»¸ö
http://www.technicalbard.com/files/MySQL-python-1.2.2.win32-py2.6.exe
°²×°ºóimport MySQLdb»á³öÏÖ DeprecationWarning: the sets module is deprecated ÕâÑùÒ»¸ö¾¯¸æ£¬googleÖ®
......

Python»ñÈ¡²Ù×÷ϵͳ°æ±¾ÐÅÏ¢

    ×î½ü£¬ÏëÔÚÎÒµÄYouMoney£¨http://code.google.com/p/youmoney/£©ÀïÃæÔö¼ÓÌáÈ¡Óû§²Ù×÷ϵͳ°æ±¾ÐÅÏ¢¡£±ÈÈçwindowsÓû§£¬¿ÉÄÜÒª·µ»ØWindows XP ,»òÕßWindows 2003, Æ»¹ûÓû§Ó¦¸Ã·µ»ØMac OS X 10.5.8¡£ÓÃÁ˺ܶà°ì·¨£¬°üÀ¨ÔÚmacϵͳÀïµ÷ÓÃϵͳÃüÁȡ»·¾³±äÁ¿£¬µÈµÈ¡£×îºóÎÞÒâ·¢ÏÖ£¬Ô­À´pythonÀïÀïÃæÓиöpl ......

Ç¿´óµÄPythonÉú³ÉÆ÷

Öð²½Ñݽø
f=open('/etc/motd','r')
longest=0
while True:
    lineLen=len(f.readline().strip())
    if not lineLen: break
    if lineLen > longest:
        longest=lineLen
f.close()
return longest
ÎÊÌâ£ºÒ»Ö±Õ¼Ó ......

pythonË㷨ʵ¼ù1 Ö±½Ó²åÈëÅÅÐò

# Ö±½Ó²åÈëÅÅÐò
def InsertSort(mylist):
size = len(mylist)
i = 1
for i in range(1, size):
if mylist[i] < mylist[i - 1]:
tmp = mylist[i]
j = i - 1
mylist[j + 1] = mylist[j]

j = j - 1
while j > ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ