回覆列表
  • 1 # 得到歷史

    def list_powerset(lst): # the power set of the empty set has one element, the empty set result = [[]] for x in lst: # for every additional element in our set # the power set consists of the subsets that don"t # contain this element (just take the previous power set) # plus the subsets that do contain the element (use list # comprehension to add [x] onto everything in the # previous power set) result.extend([subset + [x] for subset in result]) return resultprint list_powerset([1,2,3])

    >>>[[], [1], [2], [1, 2], [3], [1, 3], [2, 3], [1, 2, 3]]

  • 中秋節和大豐收的關聯?
  • 3.3V電壓4-6只led燈1.5v20ma串聯取多大電阻值?