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

Python Á·Ï°2

Éú³ÉÒ»¸öÓÐN¸öÔªËصÄÓÐËæ»úÕûÊýn×é³ÉµÄÁÐ±í£¬ÆäÖÐNºÍÄêµÄÈ¡Öµ·¶Î§ÊÇ£¨1<N<=5£©
ºÍ(0<=n<100)£¬ÏÔʾÕâ¸öÁбíµÄËùÓÐ×Ó¼¯¡£
N¸öÊý×Ö¿ÕÓÐ2en¸ö×Ó¼¯£¬¶ÔÓÚÕâN¸öÊý×ÖÔÚÿ¸ö×Ó¼¯ÖÐÀ´½²ÒªÃ´´æÔÚҪô²»´æÔÚ£¬¿ÉÒÔ²ÉÓÃ×Ó¼¯Ó³ÉäΪ2½øÖƵÄËã·¨¡£
ÀýÈç[a,b]¼¯ºÏµÄ×Ó¼¯£º
¿Õ      ----       00
a       ----       10
b       ----       01
ab     ----       11
Òò´ËÎÊÌâ¼ò»¯ÎªÁгöËùÓÐСÓÚ2enµÄÊý×ÖµÄ2½øÖÆÐÎʽ£¬½«Æä¶ÔÓ¦¼´¿É
#!/usr/bin/python
import random
def bin(x):
x=int(x)
if x==0:
return str(0)
else:
result=''
while x>0:
mod=x%2
x=x/2
result=str(mod)+result
return result

def getAllSubset(aList):
allSubset=[]
aListLen=len(aList)
combination=pow(2,aListLen)
for i in range(combination):
str2=bin(i)
differ=aListLen-len(str2)
str2=''.join(['0' for i in range(differ)])+str2
subset=[]
for j in range(aListLen):
if int(str2[j])==1:
subset.append(aList[int(j)])
allSubset.append(subset)
return allSubset
if __name__ == "__main__":
num=random.randint(2,5)
aList=[random.randint(0,100) for i in range(num)]
allSubset=getAllSubset(aList)
print allSubset

  


Ïà¹ØÎĵµ£º

Python¼òÒ×¹ÉƱ²éѯ(ץȡgoogle²Æ¾­µÄÄÚÈÝ)


¿´×ÅÍøÉÏץȡÍøÒ³Êý¾ÝµÄÎÄÕÂÖ±µÉÑÛ
ºóÀ´Ïëµ½ÓÃ×Ö·û´®·Ö¸îÀ´ÌáÈ¡ÏàÓ¦²¿·ÖµÄÄÚÈÝ
³ÌÐò¼òµ¥£¬µ«ÊýÐÐÊýºÍϱê·ÑÁ˺ܳ¤Ê±¼ä
ÎÒÖªµÀÕâ¿Ï¶¨²»ÊÇ×îºÃµÄ°ì·¨- -!!
µ«ÎÒʵÏÖÁË£¬¹þ¹þ
# -*- coding: cp936 -*-
from urllib import *
import re
def stockSearch():
    baseurl="http://www.google.cn/financ ......

Python for win

Python²Ù×÷Excel·½·¨£º
£¨1£©ÔÚsourceforge.netÉÏÓÐÒ»¸öÀ©Õ¹Ä£¿é½ÐpyXLWriter£¬¿ÉÒÔ·½±ãµÄдExcelÎļþ¡£
£¨2£©ÏÂÔØwin32com°ü×°ÉÏ,Õâ¸ö°ü¿ÉÒÔµ÷ÓÃwindowsµÄcom¼°APIº¯ÊýµÈÕâÀàµÄ¹¦ÄÜ¡£PythonÀûÓÃwin32com²Ù×÷Excel¡£
Àý×Ó£º
#!/usr/bin/env python  
# -*- coding: utf-8 -*-  
from win32com. ......

PythonÀïÒþ²ØµÄ¡°ìø¡±

ÔÚ pythonµÄlibĿ¼ÀïÓÐÒ»¸ö£ºthis.py£¬ËüÆäʵÊÇÒþ²Ø×ÅÒ»Ê×Ê«£¬Ô´ÂëÈçÏ£º
s =
"""Gur Mra bs Clguba, ol Gvz Crgref

Ornhgvshy vf orggre guna htyl.
Rkcyvpvg vf orggre guna vzcyvpvg.
Fvzcyr vf orggre guna pbzcyrk.
Pbzcyrk vf ......

Pythonѧϰ±Ê¼Ç Îļþ¶Áд

PythonÖÐÎļþ²Ù×÷¿ÉÒÔͨ¹ýopenº¯Êý£¬ÕâµÄÈ·ºÜÏñCÓïÑÔÖеÄfopen¡£Í¨¹ýopenº¯Êý»ñÈ¡Ò»¸öfile object£¬È»ºóµ÷ÓÃread()£¬write()µÈ·½·¨¶ÔÎļþ½øÐжÁд²Ù×÷¡£
1.open
ʹÓÃopen´ò¿ªÎļþºóÒ»¶¨Òª¼ÇµÃµ÷ÓÃÎļþ¶ÔÏóµÄclose()·½·¨¡£±ÈÈç¿ÉÒÔÓÃtry/finallyÓï¾äÀ´È·±£×îºóÄܹرÕÎļþ¡£
file_object = open('thefile.txt') ......

[Python and or ]Python ÖÐ and or Ö® ÎÒµÄÀí½â

c´úÂë:
int x = a>b?6,6;
ÕâÖÖÓï¾äPythonÖÐÒ²ÓУº
¿ÉÒÔͨ¹ýand or×éºÏÀ´ÊµÏÖ¡£¸öÈËÈÏΪÕâÖÖÓï¾ä¾¡Á¿ÉÙµãºÃ¡£
python°ÑÕâÀàÐ͵ŦÄÜ·¢Ñï¹âÁË´ó¡£µ«ÊÇÓÉÓÚÕâÖÖ×éºÏ±È½ÏÈÆ£¬ËùÒÔÓÐʱºò±È½Ï¾À½á:
±ÈÈç:
5 or 6 and 6  ·µ»Øwhat?
0 or 5  ·µ»Øwhat?
8 and 7  ·µ»Øwhat?
ÓÚÊÇÕûÀíÁËÏ£º
1.pyhon ÖÐÓ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ