forked from pybites/challenges
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated readme files to point to our code challenge articles with ins…
…tructions, don't repeat yourself (DRY)
- Loading branch information
Showing
9 changed files
with
20 additions
and
571 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,5 @@ | ||
## Code Challenge 01 - Word Values Part I | ||
|
||
### Calculate the (language) dictionary word that would have the most value in Scrabble | ||
Instructions [here](http://pybit.es/codechallenge01.html). | ||
|
||
Read in dictionary.txt (provided, just a copy of /usr/share/dict/words of my Mac) and calculate the word that has the most value in Scrabble based on LETTER_SCORES which is imported from data.py in wordvalue-template.py. | ||
|
||
Make sure you run the test_wordvalue.py to verify your methods are correct. | ||
It expects (imports) wordvalue.py so make sure you copy wordvalue-template.py to wordvalue.py | ||
|
||
Note that no PyPI modules need to be installed, just use stdlib for this. | ||
|
||
Bonus: something to think about: when calculating the max value can you use a fast builtin method? And even so could you improve the performance even further? | ||
|
||
Enjoy! | ||
|
||
### About PyBites Code Challenges | ||
|
||
Read [our intro post](http://pybit.es/codechallenge01.html) or this repo's [README](https://github.com/pybites/challenges) for more info how it works. | ||
|
||
Please be patient as we are still learning how to best present the code challenges and collaborate on Github. | ||
|
||
We think working towards tests is a good approach (TDD). Also for starters we will be providing stubs (see wordvalue-template.py) to lower the entry-level. However if you have any other ideas or feedback please [let us know](https://github.com/pybites/challenges/issues). | ||
|
||
Thanks for trying! | ||
Previous challenges and About [here](http://pybit.es/pages/challenges.html). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,95 +1,5 @@ | ||
## Code Challenge 02 - Word Values Part II - a simple game | ||
|
||
> This week, each one of you has a homework assignment ... - Tyler Durden (Fight club) | ||
Instructions [here](http://pybit.es/codechallenge02.html). | ||
|
||
### Given a random set of 7 letters build the most valuable word | ||
|
||
Using what we've learned [the last challenge](http://pybit.es/codechallenge01.html) this week we build a simple Scrabble-like game (without board): | ||
|
||
Letters drawn: G, A, R, Y, T, E, V | ||
Form a valid word: gary << user input | ||
Word chosen: GARY (value: 8) | ||
Optimal word possible: GARVEY (value: 13) | ||
You scored: 61.5 | ||
|
||
### Get ready | ||
|
||
Start coding by [forking our challenges repo](https://github.com/pybites/challenges): | ||
|
||
$ git clone https://github.com/pybites/challenges | ||
|
||
If you already forked it [sync it](https://help.github.com/articles/syncing-a-fork/): | ||
|
||
# assuming using ssh key | ||
$ git remote add upstream [email protected]:pybites/challenges.git | ||
$ git fetch upstream | ||
# if not on master: | ||
$ git checkout master | ||
$ git merge upstream/master | ||
|
||
Use one of the templates: | ||
|
||
$ cd 02 | ||
$ cp game-TEMPLATE.py game.py | ||
# code | ||
|
||
### Requirements / steps | ||
|
||
Last time we provided unittests and a guiding template. We received feedback that this was a bit too stringent. Therefore we provide two templates this time: game-help.py and game-nohelp.py | ||
|
||
* We load in the necessary data structures to focus on the game: | ||
|
||
# Note that DICTIONARY is a set for O(1) lookups | ||
from data import DICTIONARY, LETTER_VALUES, POUCH | ||
|
||
* Draw 7 random letters from POUCH. | ||
|
||
As said POUCH is given and contains a distribution of Scrabble letters so that the player gets enough vowels (equally drawing A-Z makes it extremely hard because you need more vowels to make words): | ||
|
||
['A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'B', 'B', 'C', 'C', | ||
'D', 'D', 'D', 'D', ...] | ||
|
||
* Ask the player to form a word with one or more of the 7 letters of the draw. Validate input for: | ||
|
||
1) all letters of word are in draw; | ||
2) word is in DICTIONARY. | ||
|
||
* Calculate the word value and show it to the player. | ||
|
||
To focus on this challenge we re-use two methods from the previous challenge for this: calc_word_value and max_word_value. | ||
|
||
* Calculate the optimal word (= max word value) checking all permutations of the 7 letters of the draw, cross-checking the DICTIONARY set for valid ones. This is a bit more advanced, but allows you to score the player (next). | ||
|
||
* Show the player what the optimal word and its value is. | ||
|
||
* Give the player a score based on the previous steps, basically: player_score / optimal_score. | ||
|
||
### Bonus (not required) | ||
|
||
The optimal solution calculation might be a bit difficult for some, that's why we stop here. But if you are feeling creative you might consider expanding this game: | ||
|
||
* Keep scores in a shelve (file, db) and notify the player when a new record is reached. | ||
|
||
* Work with hints and bonuses: hints cost x points, give a bonus of y points, for example when a 7 letter word is created (complete draw exhausted). | ||
|
||
* Make a simple web, mobile app or pygame. | ||
|
||
### Good luck! | ||
|
||
Remember: there is no best solution, only learning more and better Python. | ||
|
||
Enjoy and we're looking forward reviewing on Friday all the cool / creative / Pythonic stuff you come up with. | ||
|
||
Have fun! | ||
|
||
--- | ||
|
||
Again to start coding [fork our challenges repo](https://github.com/pybites/challenges) or [sync it](https://help.github.com/articles/syncing-a-fork/). | ||
|
||
--- | ||
|
||
### About PyBites Code Challenges | ||
|
||
More background in our [first challenge article](http://pybit.es/codechallenge01.html). | ||
|
||
Above challenge appeared on our blog as [this article](http://pybit.es/codechallenge02.html). | ||
Previous challenges and About [here](http://pybit.es/pages/challenges.html). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,94 +1,5 @@ | ||
## Code Challenge 03 - PyBites blog tag analysis | ||
|
||
> This week, each one of you has a homework assignment ... - Tyler Durden (Fight club) | ||
Instructions [here](http://pybit.es/codechallenge03.html). | ||
|
||
### Given our RSS feed what tags does PyBites mostly use and which tags should be merged (based on similarity)? | ||
|
||
Example output: | ||
|
||
$ python tags.py | ||
|
||
* Top 10 tags: | ||
python 10 | ||
learning 7 | ||
tips 6 | ||
tricks 5 | ||
github 5 | ||
cleancode 5 | ||
best practices 5 | ||
pythonic 4 | ||
collections 4 | ||
beginners 4 | ||
|
||
* Similar tags: | ||
game games | ||
challenge challenges | ||
generator generators | ||
|
||
### Get ready | ||
|
||
Start coding by [forking our challenges repo](https://github.com/pybites/challenges): | ||
|
||
$ git clone https://github.com/pybites/challenges | ||
|
||
If you already forked it [sync it](https://help.github.com/articles/syncing-a-fork/): | ||
|
||
# assuming using ssh key | ||
$ git remote add upstream [email protected]:pybites/challenges.git | ||
$ git fetch upstream | ||
# if not on master: | ||
$ git checkout master | ||
$ git merge upstream/master | ||
|
||
Use one of the templates: | ||
|
||
$ cd 03 | ||
$ cp tags-help.py tags.py | ||
# or: | ||
$ cp tags-nohelp.py tags.py | ||
# code | ||
|
||
# run the unittests (optional) | ||
$ python test_tags.py | ||
... | ||
---------------------------------------------------------------------- | ||
Ran 3 tests in 0.155s | ||
|
||
OK | ||
|
||
|
||
### Requirements / steps | ||
|
||
* As we update our blog regularly we provided a recent copy of our feed in the 03 directory: rss.xml. We also provided a copy of tags.html for verification (used by unittests in test_tags.py). | ||
|
||
* Both templates provide 3 constants you should use: | ||
|
||
TOP_NUMBER = 10 | ||
RSS_FEED = 'rss.xml' | ||
SIMILAR = 0.87 | ||
|
||
* Rest is documented in the methods docstrings. Again use tags-help.py if you need more guidance, tags-nohelp.py is for the more experienced and/or if you want more freedom. Same goes for tests: use them if you need them. | ||
|
||
* Talking about freedom feel free to use our [live feed](http://pybit.es/feeds/all.rss.xml) but then the tests will probably break. | ||
|
||
* Hint: for word similarity feel free to use NLTK, or your favorite language processing tool. However, stdlib does provide a nice way to do this. Using this method we came to 0.87 as a threshold to for example not mark 'python' and 'pythonic' as similar. | ||
|
||
### Good luck! | ||
|
||
Remember: there is no best solution, only learning more and better Python. | ||
|
||
Enjoy and we're looking forward reviewing on Friday all the cool / creative / Pythonic stuff you come up with. | ||
|
||
Have fun! | ||
|
||
--- | ||
|
||
Again to start coding [fork our challenges repo](https://github.com/pybites/challenges) or [sync it](https://help.github.com/articles/syncing-a-fork/). | ||
|
||
--- | ||
|
||
### About PyBites Code Challenges | ||
|
||
More background in our [first challenge article](http://pybit.es/codechallenge01.html). | ||
|
||
Above challenge appeared on our blog as [this article](http://pybit.es/codechallenge03.html). | ||
Previous challenges and About [here](http://pybit.es/pages/challenges.html). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,112 +1,5 @@ | ||
## Code Challenge 04 - Twitter data analysis Part 1: get the data | ||
|
||
> This week, each one of you has a homework assignment ... - Tyler Durden (Fight club) | ||
Instructions [here](http://pybit.es/codechallenge04.html). | ||
|
||
### Write a class to retrieve tweets from the Twitter API | ||
|
||
In this 3 part challenge you will analyze Twitter Data. This week we will automate the retrieval of data. In Part 2 we will task you with finding similar tweeters, and for Part 3 you will do a full sentiment analysis. | ||
|
||
### Get ready | ||
|
||
Start coding by [forking our challenges repo](https://github.com/pybites/challenges): | ||
|
||
$ git clone https://github.com/pybites/challenges | ||
|
||
If you already forked it [sync it](https://help.github.com/articles/syncing-a-fork/): | ||
|
||
# assuming using ssh key | ||
$ git remote add upstream [email protected]:pybites/challenges.git | ||
$ git fetch upstream | ||
# if not on master: | ||
$ git checkout master | ||
$ git merge upstream/master | ||
|
||
### Setup virtual environment and install requirements | ||
|
||
$ cd 04 | ||
$ python3 -m venv venv | ||
# = py3 (might need virtualenv for py2 env) | ||
|
||
$ source venv/bin/activate | ||
# install tweepy (and its depencencies) | ||
$ pip install -r requirements.txt | ||
|
||
# if you want to use another package like twython, feel free to do so | ||
|
||
# get your API keys from Twitter - https://apps.twitter.com | ||
$ cp config-template.py config.py | ||
# paste the keys in config.py | ||
|
||
# choose a template | ||
$ cp usertweets-help.py usertweets.py | ||
# or | ||
$ cp usertweets-nohelp.py usertweets.py | ||
# code | ||
|
||
### The challenge | ||
|
||
* Define a class called UserTweets that takes a Twitter handle / user in its constructor. it also receives an optional max_id parameter to start from a particular tweet id. | ||
* Create a tweepy API object using the tokens imported from config.py (again, you can use another package if you prefer). | ||
|
||
* Create an instance variable to hold the last 100 tweets of the user. | ||
|
||
* Implement len() and getitem() magic (dunder) methods to make the UserTweets object iterable. | ||
|
||
* Save the generated data as CSV in the data subdirectory: data/some_handle.csv, columns: id_str,created_at,text | ||
|
||
### Background | ||
|
||
* We posted two articles this week you might find useful in this context: [oop primer](http://pybit.es/oop-primer.html) and [Python's data model](http://pybit.es/python-data-model.html). | ||
|
||
* If you decide to use Tweepy, you might want to check its [API reference](http://docs.tweepy.org/en/v3.5.0/api.html). | ||
|
||
### Tests | ||
|
||
For developers that like to work towards tests we included test_usertweets.py: | ||
|
||
$ python test_usertweets.py | ||
... | ||
---------------------------------------------------------------------- | ||
Ran 3 tests in 0.001s | ||
|
||
OK | ||
|
||
### Example output | ||
|
||
We used a namedtuple here, this is not required. Also note the tweets can differ, yet in the unittests we test a fix set (using the optional max_id parameter in the constructor): | ||
|
||
$ python | ||
>>> from usertweets import UserTweets | ||
>>> pybites = UserTweets('pybites') | ||
>>> len(pybites) | ||
100 | ||
>>> pybites[0] | ||
Tweet(id_str='825629570992726017', created_at=datetime.datetime(2017, 1, 29, 9, 0, 3), text='Twitter digest 2017 week 04 https://t.co/L3njBuBats #python') | ||
>>> ^D | ||
(venv) [bbelderb@macbook 04 (master)]$ ls -lrth data/ | ||
... | ||
-rw-r--r-- 1 bbelderb staff 14K Jan 29 21:49 pybites.csv | ||
(venv) [bbelderb@macbook 04 (master)]$ head -3 data/pybites.csv | ||
id_str,created_at,text | ||
825629570992726017,2017-01-29 09:00:03,Twitter digest 2017 week 04 https://t.co/L3njBuBats #python | ||
825267189162733569,2017-01-28 09:00:05,Code Challenge 03 - PyBites blog tag analysis - Review https://t.co/xvcLQBbvup #python | ||
|
||
### Good luck! | ||
|
||
Remember: there is no best solution, only learning more and better Python. | ||
|
||
Enjoy and we're looking forward reviewing on Friday all the cool / creative / Pythonic stuff you come up with. | ||
|
||
Have fun! | ||
|
||
--- | ||
|
||
Again to start coding [fork our challenges repo](https://github.com/pybites/challenges) or [sync it](https://help.github.com/articles/syncing-a-fork/). | ||
|
||
--- | ||
|
||
### About PyBites Code Challenges | ||
|
||
More background in our [first challenge article](http://pybit.es/codechallenge01.html). | ||
|
||
Above challenge appeared on our blog as [this article](http://pybit.es/codechallenge04.html). | ||
Previous challenges and About [here](http://pybit.es/pages/challenges.html). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,5 @@ | ||
## Code Challenge 05 - Twitter data analysis Part 2: how similar are two tweeters? | ||
|
||
> This week, each one of you has a homework assignment ... - Tyler Durden (Fight club) | ||
Instructions [here](http://pybit.es/codechallenge05.html). | ||
|
||
### Birds of a feather | ||
|
||
A new week, more coding! In Part 2 of our Twitter data analysis we challenge you to find out how similar two tweeters are ... | ||
|
||
### Challenge | ||
|
||
* Make a script that receives two command line args: user1 and user2 | ||
|
||
$ similar_tweeters.py bbelderbos pybites | ||
# ... some index of similarity ... | ||
|
||
* Get the last n tweets of these users. You can use the code of [Part 1](https://github.com/pybites/challenges/blob/solutions/04/usertweets.py). | ||
|
||
* Tokenize the words in the tweets, filtering out stop words, URLs, digits, punctuation, words that only occur once or are less than 3 characters (and/or other noise ...) | ||
|
||
* Extract the main subjects the users tweet about. You could use [Gensim](https://radimrehurek.com/gensim/), an NLP package for Topic Modeling. However feel free to take your own approach! We are dropping the template and requirements.txt for this challenge, we'd love to see different approaches to this problem ... | ||
|
||
* Compare the subjects and come up with a similarity score. | ||
|
||
### Stay in sync with PyBites challenges repo | ||
|
||
Start coding by [forking our challenges repo](https://github.com/pybites/challenges): | ||
|
||
$ git clone https://github.com/pybites/challenges | ||
|
||
If you already forked it [sync it](https://help.github.com/articles/syncing-a-fork/): | ||
|
||
# assuming using ssh key | ||
$ git remote add upstream [email protected]:pybites/challenges.git | ||
$ git fetch upstream | ||
# if not on master: | ||
$ git checkout master | ||
$ git merge upstream/master | ||
# ... no template for this challenge ... | ||
|
||
### Good luck! | ||
|
||
Remember: there is no best solution, only learning more Python. | ||
|
||
Enjoy and we're looking forward reviewing our and your solutions on Friday. | ||
|
||
Have fun! | ||
|
||
--- | ||
|
||
### About PyBites Code Challenges | ||
|
||
More background in our [first challenge article](http://pybit.es/codechallenge01.html). | ||
|
||
Above challenge appeared on our blog as [this article](http://pybit.es/codechallenge05.html). | ||
Previous challenges and About [here](http://pybit.es/pages/challenges.html). |
Oops, something went wrong.