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
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
In the previous post we discussed iterating through a list of lists for accessing values. But what about assigning values? Of course because of mutation the following code definitely works: but what about this one? It works also! And now, what about this one? No, that does not work! That’s an example of Python mutation… Continue reading Change a value in a list of lists