<p>从文件中的一个列表中,我试图得到两个被划分的新列表:子集合a和子集合B。这意味着子集合a中的元素(整数)应该等于子集合B。(这个程序使用回溯来顺便解决问题。)但是我得到:</p>
<pre><code>Subset A: <map object at 0x311b110>
Subset B: <map object at 0x311b190>
</code></pre>
<p>还有一个错误:</p>
<pre><code> line 93, in getSuccessors
cfgA.subA.append(config.input[config.index])
TypeError: 'map' object is not subscriptable
</code></pre>
<p>我在图中指出的构造函数是:</p>
<pre><code>def mkPartitionConfig(filename):
"""
Create a PartitionConfig object. Input is:
filename # name of the file containing the input data
Returns: A config (PartitionConfig)
"""
pLst = open(filename).readline().split()
print(pLst)
config = PartitionConfig
config.input = map(int, pLst)
config.index = 0
config.subA = []
config.subB = []
return config
</code></pre>
<p>我得到一个错误的函数:</p>
<pre><code>def getSuccessors(config):
"""
Get the successors of config. Input is:
config: The config (PartitionConfig)
Returns: A list of successor configs (list of PartitionConfig)
"""
cfgA = deepcopy(config)
cfgB = deepcopy(config)
cfgA.subA.append(config.input[config.index])
cfgB.subB.append(config.input[config.index])
cfgA += 1
cfgB += 1
return [configA, configB]
</code></pre>
<p>我在这里做错什么了?你知道吗</p>