Learn practical skills, build real-world projects, and advance your career
Created 4 years ago
NLP Course 2 Week 1 Lesson : Building The Model - Lecture Exercise 02
Estimated Time: 20 minutes
Candidates from String Edits
Create a list of candidate strings by applying an edit operation
Imports and Data
# data
word = 'dearz' # 🦌
Splits
Find all the ways you can split a word into 2 parts !
# splits with a loop
splits_a = []
for i in range(len(word)+1):
splits_a.append([word[:i],word[i:]])
for i in splits_a:
print(i)
['', 'dearz']
['d', 'earz']
['de', 'arz']
['dea', 'rz']
['dear', 'z']
['dearz', '']
# same splits, done using a list comprehension
splits_b = [(word[:i], word[i:]) for i in range(len(word) + 1)]
for i in splits_b:
print(i)
('', 'dearz')
('d', 'earz')
('de', 'arz')
('dea', 'rz')
('dear', 'z')
('dearz', '')