Data Structures and Algorithms with Object-Oriented Design Patterns in Python。This book presents material identified in the Computing Curricula 1991 report of the ACM/IEEE-CS Joint Curriculum Task Force[47]. The book specifically addresses the following knowledge units: AL1: Basic Data structures, AL2: Abstract Data Types, AL3: Recursive Algorithms, AL4: Complexity Analysis, AL6: Sorting and Searching, and AL8: Problem-Solving Strategies. The breadth and depth of coverage is typical of what should appear in the second or third year of an undergraduate program in computer science/computer engineering.
Python是一种解释性的,面向对象的,具有动态语义的高级程序设计语言。它内建高级数据结构,配以动态类型和动态捆绑,使其在快速应用开发中非常有利,就像脚本或粘合语言一样将已存在的构件连接在一起。Python的简单性和句法的易学性使其代码具有优秀的可读牲,因此维护程序的成本得以大大降低。Python具有模块和包的概念,以支持程序的模块化和代码重用。在主流平台上, Python的解释器和大量标准库都可以免费地以源代码形式或可执行文件形式获得,并且可以自由发布。
代码 import struct import ctypes def test_struct(buf, offset): return struct.unpack_from("I", buf, offset)[0] def test_ctypes(buf, offset): return ctypes.c_uint32.from_buffer(buf, offset).value def test
去掉添加到最终的结果集中,直到两个子序列归并完成。 代码如下: #!/usr/bin/python import sys def merge(nums, first, middle, last):
相比于Django而言,bottle显得非常轻量级。短短几行代码即可快速搭建一个简易的http server。提供了 Python Web开发中需要的基本支持:URL路由,Request/Response对象封装,模板支持,
Python识别验证码 #encoding=utf-8 import Image,ImageEnhance,ImageFilter import sys image_name = "./1.jpeg"
通过调用GetSystemPowerStatus Windows Api来判断AC Power是开启还是关闭状态。是一个python调用windows api的例子。 import os import win32con import
http://pymssql.sourceforge.net/ 下载pymssql模块,必须安装这个模块才可以用python连接mysql 以下是简单的访问代码,需要注意字符集 # -*- coding:gbk -*-
如果下载小文件,可以直接使用urllib.urlretrieve方法: import urllib urllib.urlretrieve ("http://www.example.com/songs/mp3.mp3", "mp3.mp3") 但是如果下载的文件尺寸很大,就不适合直接urlretrieve了。我们需要按块读取文件来下载: import urllib2 url = "http://do
使用 MySQLdb 模块连接 MySQL # coding=utf-8 #引入mysql python客户端模块 import MySQLdb import sys #进行数据库连接 conn = MySQLdb
下面的函数封装了系统的grep功能,传递文件名和参数返回grep的结果 import subprocess def grep(filename, arg): process = subprocess.Popen(['grep', '-n', arg, filename], stdout=subprocess.PIPE) stdout, stderr = process.communicate()
本代码可以帮你自动剪切掉图片的边缘空白区域,如果你的图片有大片空白区域(只要是同一颜色形成一定的面积就认为是空白区域),下面的python代码可以帮你自动切除,如果是透明图像,会自动剪切大片的透明部分。 本代码需要PIL模块 import
/usr/bin/env python # # [SNIPPET_NAME: Dictionaries 101] # [SNIPPET_CATEGORIES: Python Core] # [SNIPPET_DESCRIPTION:
parseFile(open("sample.xml")) parser.close() 7.python的GUI模块标准的是Tkinter,也有QT和MFC的模块,有兴趣的大家自己搜索下 import
Caesar算法是最简单的加解密算法... # Caeser Cipher import sys,os MyCypher = 25 MyDict = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz `1234567890-=~!@#$%^&*()_+[]\\;\',./{}|:"<>?' plaintext = 'Hello World!
使用前请先安装openpyxl: easy_install openpyxl 通过这个模块可以很方便的导出数据到Excel from openpyxl.workbook import Workbook from openpyxl.writer.excel import ExcelWriter from openpyxl.cell import get_column_letter from open
1.冒泡排序 比较相邻的元素大小,将小的前移,大的后移,就像水中的气泡一样,最小的元素经过几次移动,会最终浮到水面上。 def bubble(list): for i in range(len(list)): for j in range(0,len(list)-1-i): if list[j] > list[j+1]: list[j],list[j+1]=list[j+1],list[j] if
''''' Bubble Sort @author: aihua.sun ''' import string import random number = []; count = 0; def bubbleSort(): #initializeNumberArray(); generateRandomNumberArray(10, 1, 300); showArray(); sort(); sho
import sys, urllib2, urllib def addGETdata(url, data): '''Adds data to url. Data should be a list or tuple consisting of 2-item lists or tuples of the form: (key, value). Items that have no key should
import sys, socket hostname = socket.gethostname() # Try to get the fully-qualified name. print 'Fully-qualified name:', socket.getfqdn(hostname)