What’s the goal?
At work, we’ve recently been playing Pictionary online game for some time now as it helps break the work routine. This can be a fun game to play with your team members. However, for me, at the scheduled time, on a Friday afternoon, my brain is already saturated. The only time I’ve managed to get good results is when I don’t have much work to do or I am on holiday the previous day.
But first, what’s Pictionary?
A guessing game in which players attempt to identify words from pictures drawn by other players. 
Out of curiosity, I want to develop a quick Python project to assist me in filtering words. Maybe I also want to win and don’t like losing. In either case, this is a good opportunity to improve my Python and overall coding skills. At this point though, I’m not going to use libraries on Natural Language Processing (NLP) or Machine Learning.
So I’m thinking about predicting the most common words based on:
- number of words
- word length
- one or two letters (bonus)
Maybe, for a start, I’ll assume only a single word.
How to get a list of words?
To initiate this quest, I visit a couple of sites to list the most common words used in Pictionary.
As I copy and paste the words into a Python list, I note that lots of words seem to be missing. Not willing to compromise on this part, I search for 10 000 common English words on Google. I skim through the GitHub gist thinking that maybe some are missing. So I try a step ahead. 20k words .
This one looks more interesting. Now the question is: how to extract this data?
How to extract the data?
I copy and paste the text into Sublime Text Editor but I can’t use the multi cursor select as I can with Visual Studio code. I would normally just hold alt + shift and page down to select all the lines appearing on the screen. There’s perhaps a way of doing it with Sublime but with a time constraint, I prefer using the other editor. Nevertheless, with the number of words present, this will take a while.
I need better leverage.
As I’m relatively proficient with VIM, I know this is possible to convert the long list of words into a Python list, especially with the use of macros. But it has been a while since I used it.
So I switch to my default tried and trusted Excel spreadsheet which I always used for data analytics and during the process of cleaning and transforming data in EDI systems.
How do I extract the data?
- Copy the raw data
- paste the list in an excel sheet
- insert a column before
- add double quotes in the previous and after columns
- also, add a comma
- then use the =concat formula
- double click on the expander
- the list of words for python is generated
I create a variable call words and add . I then paste the data inside of the list.
How to process this data?
There are several ways of processing data with Python including the default list data structure or the use of numpy for multidirectional arrays or Pandas Dataframes which are highly popular in the data science and analytics community.
Getting started with the project
How to install flask?
python -m pip install flask
How to run flask server?
python -m flask run
This is the command I’m using to run the Flask project so that I can specify localhost and the port number. I’m already using the default port 5000 for API development.
python -m flask run --host=0.0.0.0 --port=4200
I’m also using the
app.run(debug) mode so that the server restarts when there is a change in files. However, you still need to press f5. I’ve not seen hot module replacement like the likes of Webpack.
Bonus Materials for setting up Flask:
VSCode flask tutorial (incl. debugging)
For the next iteration, I’ll be focusing on implementing the UI using Bootstrap in the simplest of manner.
Once done, I’ll then work on the logic.
I don’t think of adding unit tests with PyTest though.
Meanwhile, what can you learn from this post?
- learning and using Python is not hard, just requires some daily effort
- building ad hoc and/or fun projects is easy as there are plenty of awesome packages out there
- you can build software on Web or Native
- Python is an easy and fun programming language for manipulating data