擅长:python、mysql、java
<p>每次迭代现有元素(在appendToList中)并且不需要在<code>subset</code>方法中分配元素时,都会进入无限循环,请检查以下内容:</p>
<pre><code>class Strings(object):
def __init__(self,string):
self.list1=[]
self.string=string
def appendToList(self,ch1):
self.list1.append(ch1)
# for i in self.list1: # no needed for loop is in subset
# self.list1.append(i+ch1)
def subset(self):
for ch in self.string:
self.appendToList(ch) # no need to assign to self.list1
print self.list1
obj=Strings('hello')
obj.subset()
</code></pre>