python真是太简单了,直接在itertools模块内置了全排列算法,你只需要一句代码既可以输出数组的全排列全排列定义:从n个不同元素中任取m(m≤n)个元素,按照一定的顺序排列起来,叫做从n个不同元素中取出m个元素的一个排列。当m=n时所有的排列情况叫全排列。from itertools import permutations#from htt……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2646浏览 2408个赞
从n个不同元素中任取m(m≤n)个元素,按照一定的顺序排列起来,叫做从n个不同元素中取出m个元素的一个排列。当m=n时所有的排列情况叫全排列。这段代码用到了yield方法,全排列速度加倍def perm(arr, pos = 0): if pos == len(arr): yield arr for i in ran……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2312浏览 451个赞
python生成全排列数从n个不同元素中任取m(m≤n)个元素,按照一定的顺序排列起来,叫做从n个不同元素中取出m个元素的一个排列。当m=n时所有的排列情况叫全排列。#coding:utf-8#全排列发生器#http://www.75271.com/codes/def a(n): li=[] for i in range……继续阅读 » 水墨上仙 4年前 (2021-03-22) 1402浏览 1682个赞
python回溯法实现数组全排列输出全排列解释:从n个不同元素中任取m(m≤n)个元素,按照一定的顺序排列起来,叫做从n个不同元素中取出m个元素的一个排列。当m=n时所有的排列情况叫全排列。from sys import stdout#code from http://www.75271.com/codes/def perm(li, start,……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2210浏览 786个赞
python标准算法实现数组全排列代码,代码来自国外网站,希望对大家有所帮助。从n个不同元素中任取m(m≤n)个元素,按照一定的顺序排列起来,叫做从n个不同元素中取出m个元素的一个排列。当m=n时所有的排列情况叫全排列。#code from http://www.75271.com/codes/def Mideng(li): if(type……继续阅读 » 水墨上仙 4年前 (2021-03-22) 1793浏览 1554个赞
常规方法实现python数组的全排列操作全排列解释:从n个不同元素中任取m(m≤n)个元素,按照一定的顺序排列起来,叫做从n个不同元素中取出m个元素的一个排列。当m=n时所有的排列情况叫全排列。def perm(l): if(len(l)<=1): return [l] r=[] for ……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2522浏览 2879个赞
png图片有些是没有背景颜色,如果希望以单色(比如白色)填充背景,可以使用下面的代码,这段代码将当前目录下的 75271.com.png图片填充了白色背景。 使用指定的颜色的背景色即可,然后把该图片用alpha通道填充到该单色背景上。 比如下面使用白色背景:……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2620浏览 1535个赞
这段代码自定义了一个类,类包含了两个成员title和url,在类的内部定义了一个函数list_all_member用于输出类的所有成员变量及值# -*- coding: utf-8 -*-#75271.com提供代码,转载请注明出处class Site(object): def __init__(self): self.ti……继续阅读 » 水墨上仙 4年前 (2021-03-22) 1731浏览 2143个赞
python格式化日期时间的函数为datetime.datetime.strftime();由字符串转为日期型的函数为:datetime.datetime.strptime(),两个函数都涉及日期时间的格式化字符串,75271.com提供详细的代码详细演示了每一个参数的使用方法及范例。 ……继续阅读 » 水墨上仙 4年前 (2021-03-22) 1640浏览 1904个赞
php XSS安全过滤代码function remove_xss($val) { // remove all non-printable characters. CR(0a) and LF(0b) and TAB(9) are allowed // this prevents some character re-spacing such a……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2053浏览 1188个赞
php逐行读取文件范例代码,通过fopen打开文件,fgets读取文件,fclose关闭文件<?php$file = fopen("welcome.txt", "r") or exit("Unable to open file!");//Output a line of the fil……继续阅读 » 水墨上仙 4年前 (2021-03-22) 1843浏览 2632个赞
我们使用SimpleXML来加载XML文件如下。<?php $xml = simplexml_load_file("sample.xml"); echo htmlspecialchars($xml->asXML());?> sa……继续阅读 » 水墨上仙 4年前 (2021-03-22) 1949浏览 2835个赞
PHP的SimpleXML扩展提供了一个非常简单和易于使用的工具集,把XML转换为可以通过数组迭代的对象。我们使用SimpleXML来加载XML文件如下。<?php $xml = simplexml_load_file("sample.xml"); var_dump($xml);?> ……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2573浏览 833个赞
下面的代码通过一个简单的范例演示了php如何读取xml文件并输出xml属性<?php $xml = simplexml_load_file("books.xml"); foreach($xml->book[0]->author->attributes() AS $a => $b) { ……继续阅读 » 水墨上仙 4年前 (2021-03-22) 1631浏览 1436个赞
下面的代码分别用于创建mysql表和上传文件保存到mysql数据库 创建mysql表<?php $con = mysql_connect("localhost", "", ""); mysql_select_……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2280浏览 1052个赞
给定一段文本,此代码分析文本的词频分布,生成tag云<?php/** * Tag cloud demo based on word frequency * @author: unknown * @since: 2007-02-27 */ // Store frequency of words in an array$freqDat……继续阅读 » 水墨上仙 4年前 (2021-03-22) 1248浏览 2282个赞
php对mysql查询结果进行分页<?php function pageSplit($startPos, $rowsPerPage = '', $totalRows = '' ) { $numPages = $totalRows / $rowsPerPag……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2782浏览 728个赞
Mail-lib提供的简单发送邮件接口, 这段代码不能在windows下运行<?php function send_mail($to_address, $from_address, $subject, $message) { $path_to_sendmail = "/usr/lib/sendmail"; ……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2603浏览 688个赞
In Recurive funaction..(code using PHP and MySql)When using a recursive function try not to use any iterative loops. It increases the number of iterations at execution time. In thi……继续阅读 » 水墨上仙 4年前 (2021-03-22) 3116浏览 2476个赞
php检测Israeli ID (9 digits)是否有效<? // takes a string and returns an array of characters function toCharArray($input){ $len = strlen($input); for ($j=0;$j<$……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2657浏览 276个赞
阿拉伯数字转换为罗马数字函数function to_roman($num) { // Function to convert an arabic number ($num) to a roman numeral. $num must be between 0 and 9,999 if ($num < 0 || $num > 9999……继续阅读 » 水墨上仙 4年前 (2021-03-22) 1702浏览 278个赞
这是一个php准确计算出复活节日期的函数<?PHP function isLeapYear( $nYEAR ) { if ((( $nYEAR % 4 == 0 ) AND !( $nYEAR % 100 == 0 )) AND ( $nYEAR % 400 != 0 )) { return TRUE; } else { ……继续阅读 » 水墨上仙 4年前 (2021-03-22) 1350浏览 2085个赞
这个php类可以识别和验证不同类型的信息卡号码<?php class credit_card { function clean_no ($cc_no) { // Remove non-numeric characters from $cc_no return ereg_replace……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2911浏览 1541个赞
给定可用的字符列表生成一个指定长度的随机字符串<? function randomString($len) { srand(date("s")); $possible="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890!@#……继续阅读 » 水墨上仙 4年前 (2021-03-22) 1617浏览 1298个赞
php字符串转换成标准标题样式<?php function titleCase($string) { $len=strlen($string); $i=0; $last= ""; $new= ""; $strin……继续阅读 » 水墨上仙 4年前 (2021-03-22) 1431浏览 2113个赞
Boolean Keywords<? /* BEGIN FUNCTION DEFINITIONS */ /* This function takes in an array and flushes all null values from the array. It returns the array - all null ……继续阅读 » 水墨上仙 4年前 (2021-03-22) 1838浏览 1917个赞
Boolean Keyword Interpreter#!/usr/local/bin/php <? /* BEGIN FUNCTION DEFINITIONS */ /* This function takes in an array and flushes all null values from the array. ……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2845浏览 875个赞
这段代码包含两个函数,bin2text,二进制转换为文本,text2bin,文本转换成二进制<? function bin2text($bin_str) { $text_str = ''; $chars = explode("\n", chunk_split(str_replace(……继续阅读 » 水墨上仙 4年前 (2021-03-22) 3029浏览 1035个赞
有了这个php类,计算函数或者一段代码的执行时间就简单了<? class c_Timer { var $t_start = 0; var $t_stop = 0; var $t_elapsed = 0; func……继续阅读 » 水墨上仙 4年前 (2021-03-22) 1289浏览 2322个赞
一组php编写的用于金融计算的函数<?php /* VARIABLES: $m = number of periods per year. For instance, if you are For instance, if you are making payments monthly the……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2023浏览 743个赞
php递归遍历多维数组<? # A recursive function to traverse a multi-dimensional array # where the dimensions are not known # function get_array_elems($arrResult, $where="ar……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2221浏览 1689个赞
php不透露实际地址的文件下载function download_document($filename, $path = "", $mimetype = "application/octet-stream"){ header("Cache-Control: must-revalidate, post……继续阅读 » 水墨上仙 4年前 (2021-03-22) 1638浏览 426个赞
这段代码用于提供下载,不是用来下载别人网站的内容的<?php $filename = $_GET['filename']; // Modify this line to indicate the location of the files you want people to be able to download/……继续阅读 » 水墨上仙 4年前 (2021-03-22) 3061浏览 1252个赞
php获得一个mysql数据查询结果if (!function_exists('mysql_fetch_results')) { function mysql_fetch_results($resource, $results = Array()) { while($row = @mysql_fetch_a……继续阅读 » 水墨上仙 4年前 (2021-03-22) 1879浏览 484个赞
php列出mysql指定数据库中的所有表if (!function_exists('mysql_list_db_tables')) { function mysql_list_db_tables($database) { $tables = Array(); $results = mysql……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2691浏览 2607个赞
php列出mysql中可用数据库的名字if (!function_exists('mysql_list_databases')) { function mysql_list_databases($resources = Array()) { $list = Array(); for ($i ……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2328浏览 1578个赞
php读取数据库生成一条一条的sql语句,可以用作mysql的备份if (!function_exists('mysql_dump')) { function mysql_dump($database) { $query = ''; $tables = @mysql_li……继续阅读 » 水墨上仙 4年前 (2021-03-22) 1683浏览 2463个赞
php5已经包含了file_pub_contents函数,这个可以用在php4中if (!function_exists('file_put_contents')) { function file_put_contents($file, $contents = '', $method = 'a……继续阅读 » 水墨上仙 4年前 (2021-03-22) 1459浏览 835个赞
php正则表达式验证邮件地址$string = "first.last@domain.co.uk"; if (preg_match('/^[^\W][a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)*\@[a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)*\.[a-zA-Z]{2,4}$/'……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2004浏览 2722个赞
这段代码演示了php中如果打包文件为zip格式function create_zip($files = array(),$destination = '',$overwrite = false) { //if the zip file already exists and overwrite is false, return fa……继续阅读 » 水墨上仙 4年前 (2021-03-22) 1414浏览 153个赞
php到处mysql数据到excel文件<?php // DB TABLE Exporter//// How to use://// Place this file in a safe place, edit the info just below here// browse to the file, enjoy! // CHA……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2332浏览 1489个赞
这段代码演示了php中如何发送html格式的邮件/*EXAMPLE: htmlmail('user@domain.com', 'Look ma, HTML e-mails','You just got <a href="http://www.yougotrickrolled.com/&……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2956浏览 1804个赞
这段代码通过各种手段来检测用户终端是否是移动设备function mobile_device_detect($iphone=true,$ipad=true,$android=true,$opera=true,$blackberry=true,$palm=true,$windows=true,$mobileredirect=false,$desktopr……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2142浏览 2036个赞
php在当前页验证表单数据URL: http://support.jodohost.com/showthread.php?t=4350<?php function VerifyForm(&$values, &$errors){ // Do all necessary form verification i……继续阅读 » 水墨上仙 4年前 (2021-03-22) 2261浏览 819个赞
这个php图片上传类功能非常完善,完全可以满足各种图片上传需求<?php/************************************** seesaw associates | http://seesaw.net client: file: description: Copyright (C) 2008 M……继续阅读 » 水墨上仙 4年前 (2021-03-22) 1271浏览 1284个赞