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
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
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
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:
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.
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
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