Skip to content

Commit

Permalink
Fix merge_delete function to add missing words to
Browse files Browse the repository at this point in the history
destination file

Improve README.
  • Loading branch information
LyubomirT committed Nov 27, 2023
1 parent 9259d16 commit c909820
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 2 deletions.
56 changes: 56 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,62 @@ word = "reactjs"
remove_from_wordlist(word)
```

If you want to remove multiple words at once, you can pass a list or a tuple to the function. Like this:

```python
from lesp import remove_from_wordlist

words = ["reactjs", "vuejs", "angularjs"]

remove_from_wordlist(words)
```

### Stacking

This function lets you stack two wordlist files together, so you can have a bigger wordlist out of two combined. The function will take two arguments, the source file and the destination file. The source file is the file that will be stacked on top of the destination file. Here's an example:

```python
from lesp import stack

stack("wordlist.txt", "my_wordlist.txt")
```

### Merge delete

This function lets you delete all words from the destination file that are in the source file. For example, if you have a wordlist with the following words:

```
apple
banana
orange
```

And you have another wordlist with the following words:

```
apple
banana
raspberry
```

Then, if you use the `merge_delete` function, the destination file will be modified to look like this:

```
orange
raspberry
```

Here's an example of how you can use it:

```python
from lesp import merge_delete

merge_delete("wordlist.txt", "my_wordlist.txt")

with open("my_wordlist.txt", "r") as f:
print(f.read())
```

## Examples 📝

If you're still not sure where to use LESP, you can check out the `examples` folder. It contains some examples of how you can use LESP in your projects. These examples are pretty simple, but they should give you an idea of how you can use LESP in your projects.
Expand Down
8 changes: 6 additions & 2 deletions lesp/autocorrect.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,14 @@ def merge_delete(source, destination):
if not all(word.isalpha() for word in destination_words):
raise ValueError("Invalid destination file format. Words must contain only alphabetic characters.")

destination_words = list(set(destination_words) - set(source_words))
destination_words_ = list(set(destination_words) - set(source_words))

# All other words in the source file that are not in the destination file will be added to the destination file

destination_words_ += [word for word in source_words if word not in destination_words]

with open(destination, "w") as f:
f.write("\n".join(destination_words))
f.write("\n".join(destination_words_))
except FileNotFoundError as e:
raise FileNotFoundError(f"File not found: {str(e)}")
except Exception as e:
Expand Down

0 comments on commit c909820

Please sign in to comment.