Python 全排列
来源:互联网 发布:淘宝联盟首页登陆 编辑:程序博客网 时间:2024/05/17 16:03
#!/usr/bin/env python# -*- coding: utf-8 -*-import osimport reimport jsonimport sysreload(sys)sys.setdefaultencoding('utf-8')''' Python 实现的全排列 递归'''def permutation(result, str, list): """ 取一个数组的全排列 list:为输入列表 str:传空字符串 result: 为结果列表 """ if len(list) == 1: result.append(str + "," + list[0]) else: uniq_dict={} for temp_str in list: temp_list = list[:] temp_list.remove(temp_str) if str == '': permutation(result, temp_str, temp_list) else: permutation(result, str + "," + temp_str, temp_list)test = []permutation(test, "", ['1', '2', '3','3'])print testdef permutation2(result, str, list): #里面有重复的元素 """ 取一个数组的全排列 list:为输入列表 str:传空字符串 result: 为结果列表 """ if len(list) == 1: result.append(str + "," + list[0]) else: uniq_dict={} for temp_str in list: if uniq_dict.has_key(temp_str): #检测是否有重复 continue else: uniq_dict[temp_str]=1 temp_list = list[:] temp_list.remove(temp_str) if str == '': permutation2(result, temp_str, temp_list) else: permutation2(result, str + "," + temp_str, temp_list)test2 = []permutation2(test2, "", ['2', '3','3'])print test2参考博客:http://blog.csdn.net/tiantiandjava/article/details/19488259
0 0
- python 全排列
- python 的全排列
- python 实现全排列
- python实现全排列
- python实现全排列
- python 全排列
- python实现全排列
- Python 全排列
- Python实现全排列
- Python全排列
- python 全排列的实现
- python 全排列 1~n
- python 全排列算法实现
- Python递归实现全排列
- python简单易懂的全排列实现
- Python,实现全排列的打印
- C++、python 写类似全排列算法
- 使用Python求一个全排列
- 微信web开发者工具 “当前代理是非安全代理” 或者“Error:unable vertify the first certification”
- Page Object Model (Selenium + Python)(三)
- 网络同步的那点事
- VBA代码实例---批量新建工作表模板升级版本
- PHP学习笔记——静态变量;
- Python 全排列
- MD5加密、URLEncoder和URLDecoder、DES加密和解密工具
- 错误:Svn process exited with error code: -1073741511
- Android系统内置下载器服务DownloadManager的使用
- Android显示圆角图片,可指定图片某几个角为圆角
- 老程序员“潜伏”多年,是该写总结的时候了!
- Oracle学习笔记一
- opencv之SURF图像匹配
- Android 优化APP 构建速度的17条建议