我有這樣一段代碼:蟒蛇: '字典' 對象有沒有屬性 '對象的has_key'
def separate_sets(self):
self.groups = {}
self.group_names = list(set(self.y))
if len(self.group_names) > 2:
print ('more than two classes provided...exiting')
sys.exit()
#putting all the samples in a regular order so that their
#grouping can be easier.
combined = sorted(zip(self.x, self.y), key = lambda n: n[1])
#--doing val,key here because (x,y) was zipped
for val,key in combined:
if self.groups.has_key(key):
self.groups[key].append(val)
else:
self.groups[key] = []
self.groups[key].append(val)
#train on each group
self.train()
我收到以下錯誤信息:
if self.groups.has_key(key):
AttributeError: 'dict' object has no attribute 'has_key'
怎麼樣的錯誤不清楚? ['has_key'已被棄用](https://docs.python.org/2/library/stdtypes.html#dict.has_key)。你有沒有使用Python 3? –