python 笔记 for loop and extend, append
list.append(item)
list.extend(sequence)
http://docs.python.org/tutorial/datastructures.html
http://docs.python.org/library/functions.html 这几天看一下
python howto
恩。python documentation 确实很好很强大啊!
list.append(x)Add an item to the end of the list; equivalent to a[len(a):] = [x].a[len(a):] 是一个list,slice得到的一个list,相当于把这一段截取出来的list,要是等于一个list b,相当于在a的末尾添加了b,但是b整个是一个元素。>>> c.append([1,2,3])>>> c[1, 2, 3, 4, [1, 2, 3]]list.extend(L)Extend the list by appending all the items in the given list; equivalent to a[len(a):] = L.
添加L中的元素,延长a
For loop, for(i=0; i<n; i++) in python is for i in range(0, n)
对于步长为2,则 for i in range(0, n, 2): range 函数可以改变步长! 不用 i += 2, Mark一下。
for i in range(0,10,2):
print i
0
2
4
6
8
比如寻找素数的程序。那么,寻找是不是被整除的时候,除了2 之外,可以从3开始,步长为2的去搜索。直到[sqrt(prime_n)](就是int(sqrt(prime_n)), 高斯函数)为止。
相关文档:
import urllib2
import time
import socket
from datetime import datetime
from thread_pool import *
def main():
url_list = {"sina":"http://www.sina.com.cn",
"sohu":"http://www.sohu.com",
"yahoo":"http://www.yahoo.com",
"xiaonei":"http://www.x ......
对于个人版,使用了.NET,安装完企业版后,看了看目录,发现大量python脚本。dll中也有sqlite3.dll
C:\Program Files\China Mobile\Efetion目录下文件:
Addin
boost_python.dll
bz2.pyd
dbghelp.dll
EFetion.exe
EFetion.exe.manifest
EFWP.exe
EFXLiveUpdate.exe
EFXLiveUpdate.exe.manifest
Face
Help.chm
......
import urllib
from HTMLParser import HTMLParser
class TitleParser(HTMLParser):
def __init__(self):
self.title = ''
self.divcontent = ''
self.readingtitle = 0
self.readingdiv = 0
HTMLParser.__init__(self)
def handle_starttag(self, tag, attrs):
......
前言:
最近又想学习python,又想去温习一下算法,于是就想出了这个两不误的方法,^_^
堆栈:
使用python的列表结构,详情可以查看help(list)
#Filename: stack.py
shoplist=['apple','mango','carrot','banana']
shoplist.append('rice')
popitem=shoplist[-1]
del shoplist[-1]
print 'the popitem is',popitem
......
#from pp3e Chapter 9.3
#############################################################################
# popup three new window, with style
# destroy() kills one window, quit() kills all windows and app; top-level
# windows have title, icon, iconify/deiconify and protocol for wm events;
# there ......