Created
June 27, 2016 15:58
-
-
Save warreee/c36e635d67661444f531ca072f0bc456 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def compare(correctList, newList, scope): | |
""" | |
A method to compare two list which are not necessarily the same but should be regarded as the same. | |
The 2 input lists are supposed to have the same items and the same length, also no duplicates are allowed. | |
Parameters | |
---------- | |
correctList: the list where the new list is compared to | |
newList: the list which is compared to the correct list | |
scope: the number of places before and behind an item | |
Returns | |
------- | |
A double which represent the percentage of comparison. | |
""" | |
correct = 0 | |
if len(correctList) != len(newList): | |
raise ValueError("List must be of equal size") | |
else: | |
for item in newList: | |
low = correctList.index(item) - scope | |
high = correctList.index(item) + scope | |
if low < 0: | |
low = 0 | |
if high > len(correctList) - 1: | |
high = len(correctList) - 1 | |
if low <= newList.index(item) <= high: | |
correct += 1 | |
return float(correct) / len(correctList) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment