파일의 목록에서 두 개의 새 목록을 나누려고합니다 : 부분 집합 A와 부분 집합 B 즉, 부분 집합 A의 요소 (정수)는 부분 집합 B와 같아야합니다. 이 프로그램은 방법으로 문제를 해결하기 위해 되돌아 사용합니다) 그러나 나는 점점 오전 :.역 추적 typeerror 파이썬
Subset A: <map object at 0x311b110>
Subset B: <map object at 0x311b190>
및 오류 :
가 line 93, in getSuccessors
cfgA.subA.append(config.input[config.index])
TypeError: 'map' object is not subscriptable
전에서지도를 표시 생성자 함수는 다음과 같습니다
을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
,
그리고 난 오류가 무엇입니까 기능 : 내가 여기에 잘못 뭐하는 거지
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]
를?
당신이지도 (INT, pLst)를 사용하는 이유는 무엇입니까? –