gsa*_*ras 1 python nameerror python-2.7
代码:
if (query_id, _) in hashtable[bucket]:
Run Code Online (Sandbox Code Playgroud)
我希望这在for循环中工作,但它会给出这个错误:
NameError:未定义全局名称"_"
hastable[bucket]如果重要的是一对列表(我怀疑).有任何想法吗?
The x in y is not magic; it's basically the same as y.__contains__(x). Therefore, in cannot search with placeholders; the left argument is fully evaluated. Instead, use
if any(query_id == qid for (qid, _) in hashtable[bucket]):
Run Code Online (Sandbox Code Playgroud)