1. 首页
  2. 数据库
  3. 其它
  4. 浅谈python输出列表元素的所有排列形式

浅谈python输出列表元素的所有排列形式

上传者: 2020-12-23 05:29:50上传 PDF文件 33.01KB 热度 68次
例如: [‘a’, ‘b’, ‘c’] 输出 [‘a’, ‘b’, ‘c’] [‘a’, ‘c’, ‘b’] [‘b’, ‘a’, ‘c’] [‘b’, ‘c’, ‘a’] [‘c’, ‘a’, ‘b’] [‘c’, ‘b’, ‘a’] 方法一:利用递归的方式实现 def permutation(li): len_list = len(li) if len_list == 1: return li result = [] for i in range(len_list): res_list = li[:i] + li[i+1:] s = li[i]
下载地址
用户评论