所以我试着把一个python转换成它的objective-c等价物,但是我运气不太好。在
Python代码如下:
def get_next_guess(passwords):
scores = {}
for candidate in passwords:
results = []
remainder = (x for x in passwords if x != candidate)
for correct_pw in remainder:
no_alternatives = len(refine(remainder, candidate, distance(candidate, correct_pw)))
print(no_alternatives)
results.append(no_alternatives)
scores[candidate] = max(results)
print(scores)
return min(scores, key = lambda x: scores[x])
我的目标是:
^{pr2}$我很感激obj-c代码非常粗糙,我只是想得到一些有用的东西。这段代码是我试图创建的解谜器的一部分。在
我怀疑(主要)问题在于obj-c版本:
remainder = (x for x in passwords if x != candidate)
Obj-c版本返回:
table: {
COELOMS = 4;
HOLLOES = 4;
MYOLOGY = 5;
PADLOCK = 5;
PARTONS = 4;
PILINGS = 6;
POMPONS = 5;
PRECESS = 6;
PROSECT = 4;
SALLOWS = 4;
TOOLERS = 5;
TROILUS = 6;
}
Python版本返回以下内容:
{'PARTONS': 3,
'HOLLOES': 3,
'PADLOCK': 4,
'TOOLERS': 4,
'COELOMS': 3,
'PROSECT': 3,
'MYOLOGY': 4,
'PRECESS': 0,
'TROILUS': 5,
'SALLOWS': 3,
'PILINGS': 4,
'POMPONS': 2}
(Python输出正确)
将
if (x != candidate)
更改为if (![x isEqualToString: candidate])
。在相关问题 更多 >
编程相关推荐