2018年1月8日 星期一

Python - get all permutation of a list w/o repetitions

from itertools import combinations

lis = [1, 2, 3, 4]
for i in range(1, len(lis) + 1):
    #range will return the values 1,2,3,4 in this loop
    print (list(combinations(lis, i)),'\n')

print (list(combinations([1, 2, 3, 4], 3)))


===================== RESTART: F:/Python_APSC/b038-2.py =====================

[(1,), (2,), (3,), (4,)] 

[(1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4)] 

[(1, 2, 3), (1, 2, 4), (1, 3, 4), (2, 3, 4)] 

[(1, 2, 3, 4)] 


[(1, 2, 3), (1, 2, 4), (1, 3, 4), (2, 3, 4)] 


>>> 

沒有留言:

張貼留言

第一次 作業 1219 ,RFID應用(四技日間部),國秀樓302教室, [選,3, 3], 四電三選7

 第一次  作業 1219 ,RFID應用(四技日間部),國秀樓302教室, [選,3, 3], 四電三選7  https://www.mediafire.com 超連結下載 https://www.mediafire.com/file/e297c5zkqaplo7z/RFID%...