我正在使用Python 2.7.
我有一个列表,我想要所有可能的有序组合.
import itertools
stuff = ["a","b","c", "d"]
for L in range(1, len(stuff)+1):
for subset in itertools.combinations(stuff, L):
print( ' '.join(subset))
Run Code Online (Sandbox Code Playgroud)
这将给出以下输出:
a
b
c
d
a b
a c <-- not in correct order
a d <-- not in correct order
b c
b d <-- not in correct order
c d
a b c
a b d <-- not in correct order
a c d <-- not in correct order
b c d
a b c d …Run Code Online (Sandbox Code Playgroud) 我错过了什么,或者这样的事情不可能吗?
class Outer:
def __init__(self, val):
self.__val = val
def __getVal(self):
return self.__val
def getInner(self):
return self.Inner(self)
class Inner:
def __init__(self, outer):
self.__outer = outer
def getVal(self):
return self.__outer.__getVal()
foo = Outer('foo')
inner = foo.getInner()
val = inner.getVal()
print val
Run Code Online (Sandbox Code Playgroud)
我收到此错误消息:
return self.__outer.__getVal()
AttributeError: Outer instance has no attribute '_Inner__getVal'
Run Code Online (Sandbox Code Playgroud)