I was browsing StackOverflow and I’ve discovered some confusion about an apparently simple Python expression:
expected == result is not None
How would you evaluate that ? Something is fishy about checking if True/False is not None isn’t it ? Well I made the same mistake and assumed some parentheses like this, but it’s wrong!
(expected == result) is not None
After I’ve read the documentation more carefully I’ve found that, although they are both comparison operators and have the same precedence, they also chain together as in: “x op1 y op2 z” is evaluated like “(x op1 y) and (y op 2 z)”. So the expression above is evaluated as follows:
(expected == result) and (result is not None)
Now that makes more sense! As a conclusion, don’t chain comparison operators in Python when it’s not obvious that they will be chained together. Choose the more obvious readable version or you will shoot somebody in the foot … maybe even yourself
April 8, 2013
I’ve been looking all day for various information about Bitcoin and other crypto-currencies and I’m fascinated by the entire fenomen. In an attempt to revolutionize the money system as we know it (or don’t know it) Satoshi and the people inspired by him have started creating a plethora of tools that allow experimenting with various economic and cryptographic models. Is a deflationary monetary system sustainable or is inflation a necessary evil ? Will a huge transaction chain be sustainable in the long run or will the distributed system fail due to security or speed issues ? Will the people use it as a value store (speculators) or value transfer (buying/selling products or services) ? Will the speculating hype raise awareness about the currency or kill it by making it too volatile?
Just wait and see what happens to Bitcoin…
- the starting point was that I like driving video games (Carmagedon, I love you) and also steering using the accelerometer was fun
- the first challenge was getting the hang of the accelerometers’ lack of sensitivity without getting dizzy
- then I got better at driving the buggy and I was starting to enjoy my new skills so that kept me going
- because I was getting better I’ve started passing more checkpoints and discovering more of the beutiful and unpredictable scenary before my time ran out, but I wanted more!
- I could also get better with power-ups and “cheats” such as “dropship 2 km ahead” so I’ve played more to get more power-ups; the alternative was paying with my credit card for them but I didn’t like to give up the challenge
- the first 600 points were given for free after the first game to “give me a head start” e.g. first drug doze is free
- I was anxious to find out what the easily bought power-up did so I kept playing … only then I realized how hard I have to work to get the second one!
- at that point I even considered buying the “collect 2 coins for 1″ cheat with real money as i did not see it as a cheat but it increased efficiency and less wasted time for me was worth much more then $2
- eventually I stopped playing when the power-ups got too expensive and the return value was no longer significant or fun