Searching for the longest word that can be written with left hand touch typing I used the following code, that uses the English words list found in https://github.com/dwyl/english-words. That gave the word ‘aftercataract’ as a result. Aftercataract does not come up as a result to this question though it’s in both Merriem-Webster and wictionary. Another… Continue reading Stewardesses, sweaterdresses and aftercataract
Stewardesses
How can we see if stewardesses is a word that can be written with only the left hand. The string with the left hand letters is ‘QWERTASDFGZXCV’, so how can we check if all the letters of an input word are in this string? A straightforward solution is: But stackoverflow has a much better suggestion… Continue reading Stewardesses
Space-time tradeoff
Yesterday Cassidy Williams (@cassidoo) sent the following problem through her newsletter (do subscribe): Assume you are given an unsorted list of numbers where everything is duplicated twice except for one number. Find and return that one number! How many solutions can you think of? Example input: [1,2,3,6,4,9,9,2,1,4,6] Example output: 3 My first solution was the… Continue reading Space-time tradeoff
The immutable string
Yesterday I wanted to print a tic-tac-toe. I wrote this: to get the grid: |—|—|—| |—|—|—| |—|—|—| And then I thought that I could compute the positions for Xs and Os. I even thought of a dict to hold them like: But Python had its own mind on the subject, when I tried: it gave:… Continue reading The immutable string
Last image standing
For a small project that hopefully will reach some level eventually. At some point after many efforts I tried the following code: This code affects only the last image (div id ttt9), the reason may be that theImg is overwritten after every each(). So the solution was: It will take me a while to get… Continue reading Last image standing
Correct number or “end” 3
Remember when I was trying to have a code for “Give a number or give ‘end’ to exit:” “Give a number or give ‘end’ to exit:” Proceeding to the amazing course I am taking our teacher gave the following solution:
Importing groupie
The following code transforms a string of zeros and ones in a form of consecutive zeros and ones. E.g., “00001110000111” will be 4,3,4,3. Without importing I had written the following code for the same task: For a minute I thought that the original code was more readable than the groupby one but I was wrong.
Generating problems
For a recent project I used groupby from itertools. I had to check the label of the first object that the groupby returns. My first guess was: that gave TypeError: ‘itertools.groupby’ object has no attribute ‘__getitem__’ my second guess was using next: And worked! The first element is now gone without return and all next… Continue reading Generating problems
Rewrite with class
For my recent project I rewrote the basic Python file. I guess the first version was just a proof of concept, it was working but it had some trouble with i,j,x,y. In order to fix those I rewrote the program. Then when it was time to commit, I had to pick one change that was… Continue reading Rewrite with class
Pyinstaller
The task of packaging a Python application is not an easy one. But for my recent Python 2.7 project the Pyinstaller did the trick. pyinstaller -F –noconsole .py