Skip to content
This repository has been archived by the owner on May 30, 2020. It is now read-only.

Commit

Permalink
more pythonic
Browse files Browse the repository at this point in the history
  • Loading branch information
filyp committed Sep 15, 2019
1 parent f87af48 commit 9fc62c5
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions autocorrect/word.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,25 @@ def __init__(self, word):

def _deletes(self):
"""th"""
return (concat(a, b[1:])
for a, b in self.slices[:-1])
for a, b in self.slices[:-1]:
yield concat(a, b[1:])

def _transposes(self):
"""teh"""
return (concat(a, reversed(b[:2]), b[2:])
for a, b in self.slices[:-2])
for a, b in self.slices[:-2]:
yield concat(a, reversed(b[:2]), b[2:])

def _replaces(self):
"""tge"""
return (concat(a, c, b[1:])
for a, b in self.slices[:-1]
for c in ALPHABET)
for a, b in self.slices[:-1]:
for c in ALPHABET:
yield concat(a, c, b[1:])

def _inserts(self):
"""thwe"""
return (concat(a, c, b)
for a, b in self.slices
for c in ALPHABET)
for a, b in self.slices:
for c in ALPHABET:
yield concat(a, c, b)

def typos(self):
"""letter combinations one typo away from word"""
Expand All @@ -70,8 +70,9 @@ def typos(self):

def double_typos(self):
"""letter combinations two typos away from word"""
return (e2 for e1 in self.typos()
for e2 in Word(e1).typos())
for e1 in self.typos():
for e2 in Word(e1).typos():
yield e2


def common(words):
Expand Down

0 comments on commit 9fc62c5

Please sign in to comment.