[Python] python 排列组合操作 →→→→→进入此内容的聊天室

来自 , 2021-01-18, 写在 Python, 查看 95 次.
URL http://www.code666.cn/view/78360091
  1. import itertools  
  2. #排列:e.g., 4个数内选2个排列
  3. >>> print list(itertools.permutations([1,2,3,4],2))  
  4. [(1, 2), (1, 3), (1, 4), (2, 1), (2, 3), (2, 4), (3, 1), (3, 2), (3, 4), (4, 1), (4, 2), (4, 3)]  
  5.  
  6. #组合:e.g.,4个数内选2个
  7. >>> print list(itertools.combinations([1,2,3,4],2))  
  8. [(1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4)]  
  9. #//python/6276

回复 "python 排列组合操作"

这儿你可以回复上面这条便签

captcha