Skip to content

Commit 8b1a2cd

Browse files
authored
Merge pull request #356 from realpython/gahjelle-python-wordle
Source code for Wyrdl SbSP
2 parents 9fb0ba0 + 2558104 commit 8b1a2cd

File tree

19 files changed

+4906
-0
lines changed

19 files changed

+4906
-0
lines changed

python-wordle/README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Build a Wordle Clone With Python and Rich
2+
3+
This repository holds the code for the Real Python [Build a Wordle Clone With Python and Rich](https://realpython.com/python-wordle-clone/) tutorial.
4+
5+
The tutorial uses the [walrus operator](https://realpython.com/python-walrus-operator/), which was introduced in [Python 3.8](https://realpython.com/python38-new-features/).
6+
7+
## Dependencies
8+
9+
The project uses [Rich](https://rich.readthedocs.io/) for style, color, and formatting in the terminal. You should first create a virtual environment:
10+
11+
```console
12+
$ python -m venv venv
13+
$ source venv/bin/activate
14+
```
15+
16+
You can then install `rich` with `pip`:
17+
18+
```console
19+
(venv) $ python -m pip install rich
20+
```
21+
22+
## Run the Application
23+
24+
Enter one of the `source_code_...` folders. You can then run the Wordle clone by running `wyrdl.py` as a script:
25+
26+
```console
27+
(venv) $ python wyrdl.py
28+
```
29+
30+
Check out the `wordlist.txt` file for a list of the words that are available (in step 2 and later). Edit this file if you want to play with your own words.
31+
32+
## Author
33+
34+
- **Geir Arne Hjelle**, E-mail: [[email protected]]([email protected])
35+
36+
## License
37+
38+
Distributed under the MIT license. See [`LICENSE`](../LICENSE) for more information.

python-wordle/requirements.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rich

python-wordle/requirements.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#
2+
# This file is autogenerated by pip-compile with python 3.11
3+
# To update, run:
4+
#
5+
# pip-compile requirements.in
6+
#
7+
commonmark==0.9.1
8+
# via rich
9+
pygments==2.14.0
10+
# via rich
11+
rich==13.0.1
12+
# via -r requirements.in
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import pathlib
2+
import sys
3+
from string import ascii_letters
4+
5+
in_path = pathlib.Path(sys.argv[1])
6+
out_path = pathlib.Path(sys.argv[2])
7+
8+
words = sorted(
9+
{
10+
word.lower()
11+
for word in in_path.read_text(encoding="utf-8").split()
12+
if all(letter in ascii_letters for letter in word)
13+
},
14+
key=lambda word: (len(word), word),
15+
)
16+
out_path.write_text("\n".join(words))

0 commit comments

Comments
 (0)