Skip to content

Instantly share code, notes, and snippets.

@warreee
Created June 27, 2016 15:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save warreee/c36e635d67661444f531ca072f0bc456 to your computer and use it in GitHub Desktop.
Save warreee/c36e635d67661444f531ca072f0bc456 to your computer and use it in GitHub Desktop.
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