Skip to content

Instantly share code, notes, and snippets.

@petartodorov
petartodorov / pep572.py
Created November 8, 2019 14:48 — forked from Hultner/pep572.py
PEP 572
# From: https://www.python.org/dev/peps/pep-0572/#syntax-and-semantics
# Handle a matched regex
if (match := pattern.search(data)) is not None:
# Do something with match
# A loop that can't be trivially rewritten using 2-arg iter()
while chunk := file.read(8192):
process(chunk)
{"Savage": "NU", "British Colony of Australia": "AU", "Espagne": "ES", "al-Ma\u0121rib": "MA", "Islas Malvinas": "FK", "Turquie": "TR", "XA-GG": "GG", "Nederlandse Antillen": "AN", "State of Israel": "IL", "Sheep Islands": "FO", "GE": "GE", "RF Yougoslavie": "YU", "GB": "GB", "\u00eb": "GL", "Dem. Rep. Korea": "KP", "Agawej": "MR", "South Korea": "KR", "R\u00e9publique f\u00e9d\u00e9rale de Yougoslavie": "YU", "\ud83c\udde9\ud83c\uddff": "DZ", "Nouvelle-Z\u00e9lande": "NZ", "\ud83c\udde9\ud83c\uddf0": "DK", "\ud83c\udde9\ud83c\uddf2": "DM", "R\u00e9publique populaire d\u00e9mocratique de Cor\u00e9e": "KP", "Republic of Iceland": "IS", "\ud83c\udde9\ud83c\uddea": "DE", "\ud83c\udde9\ud83c\uddef": "DJ", "Republic of Congo": "CG", "\u00c9tat de Palestine": "PS", "the Netherlands": "NL", "\ud83c\uddf2\ud83c\uddf7": "MR", "\ud83c\uddf2\ud83c\uddf0": "MK", "\ud83c\uddf2\ud83c\uddf1": "ML", "\ud83c\uddf2\ud83c\uddf2": "MM", "\ud83c\uddf2\ud83c\uddf3": "MN", "\ud83c\uddf2\ud83c\uddfc": "MW", "\ud83c\uddf2\ud83c\uddfd
from stringdist import levenshtein_norm as ndld
def bigram_ndld(x, y):
"""Function to check if the n-gram x matches a n-gram in the reference string y"""
n = len(x.split())
ngram = ngrams(y.split(), n)
ngram = list(ngram)
if len(ngram) == 0:
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.