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
There are many ways to iterate through a list of lists in Python, this one is nice for some cases: but when there is no need for indexing the following will work perfectly:
Using tkinter I wanted to make something happen but only if the mouse moves from one square to the next. In order to do so, I wanted to have the square coordinates the mouse was clicked and compare it with the one it is now. The prevPos variable serves this purpose. It has a global… Continue reading The global local dipole
I wrote the following code to transform a series of comma separated numbers to alternating zeros and ones e.g. 4,3,4,3 is 00001110000111. But it could be so much better like so: My insight is that when the code goes bit by bit or character by character there must be a better way.
I used this code to flip a variable from 0 to 1 and vice versa: but stackoverflow suggests better ones, I prefer the following:
I made a python reader and writer for the image representation CSUnplugged activity. You can even download it for Windows. What I learned (the hard way) is that i corresponds to y (vertical), and j corresponds to x (horizontal), e.g.
The following program could not compute current days e.g. May 15, 2017. But it could compute my birth date. The reason was the Integer type in line 2. I changed that to Longint and it did the trick. var daysBetween: Longint; So, if you are old enough, born before September 30, 1989 an integer can… Continue reading Too old to signed int