Skip to content

Instantly share code, notes, and snippets.

@igponce
Created August 24, 2020 16:53
Show Gist options
  • Save igponce/8c083447d38f4715874f3a1a4569fd40 to your computer and use it in GitHub Desktop.
Save igponce/8c083447d38f4715874f3a1a4569fd40 to your computer and use it in GitHub Desktop.
# Somewhere at start
# for instance,
if __name__ == "__main__"
self.regex = re.compile(row['keywords'],re.I|re.M)
self.matches = re.finditer(regex, x)
# Later on...
def get_iso2(x, regex, matches):
iso2={}
for j in ....
for m in matches:
iso2[row['iso2']] = iso2.get(row['iso2'], 0) + 1
return [key for key, value in iso2.items() for _ in range(value)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment