日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

求一个集合的所有子集 Python实现

發布時間:2025/4/5 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 求一个集合的所有子集 Python实现 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

求一個集合的所有子集 Python實現

#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Sat Jun 23 16:59:07 2018@author: luogan """def PowerSetsBinary(items): #generate all combination of N items N = len(items) #enumerate the 2**N possible combinations set_all=[]for i in range(2**N):#print('i=',i)#print('__'*10)combo = [] for j in range(N): #print('j=',j)#test jth bit of integer i if(i >> j ) % 2 == 1: print('i=',i,'j=',j)combo.append(items[j]) #print(combo)#yield combo #print(combo)set_all.append(combo)return set_alla=list(range(3))out= PowerSetsBinary(a)print(out [[], [0], [1], [0, 1], [2], [0, 2], [1, 2], [0, 1, 2]]

posted on 2018-06-23 17:12 luoganttcc 閱讀(...) 評論(...) 編輯 收藏

總結

以上是生活随笔為你收集整理的求一个集合的所有子集 Python实现的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。