如果我有两个列表,每个列表的元素可以是两个可能值之一,并且这两个列表除了一个值外完全相同,我应该使用哪种方法来查找该值的索引?我将在 Python 中对此进行编码作为背景信息
方法一:
1. represent both lists as a binary literals
2. use XOR on the two binary literals to give a value "v" that is a power of 2
3. finally, use math.log(v, 2) to get the index
或方法B:
just iterate through both lists until a different element is found and
get the index
还是使用 Python 的其他方式?
最佳答案
将您的列表转换为另一种表示形式将涉及遍历它们 - 还不如遍历以找到差异本身。
关于python - 在Python中查找两个列表之间单个不同元素的索引的有效方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17500201/