Why I wish Python had assignment in conditionals
There's a lot of times where a function wants to return more than aplain boolean; for example, validation routines often want to returnsome sort of explanation of the validation error (if there is one).At the same time, the most natural way to use the function is oftenin the flow of a conditional:
if blah(o): ....elif not validates(o): # whoops, lost the error reason
There's a variety of traditional answers to this,
好心做壞事
翅膀三種
2. 下文刪成670多字登在上星期日明報,應該是第一次寫劇評,手忙腳亂的——鄧正健說《臨流鳥》引發他一直存在的困惑,見說便心裡一凜,想要好好寫出更有條理和深度的才貼出來——
Thinking about the Python equivalents of C's !! double negation
C's !! double negation idiom is a way of compressing all non-zerovalues of an expression down into a 1. There's a number of things thatyou can use to get the same effect in Python:
- if you know that your result is always zero or positive, you can use
cmp(). I'm ambivalent about whether this is obscure usage; you'reat least making it clear what you're doing, although probably not why.(If your result can be
為甚麼你去clubbing的時候沒有男人埋身
每次也很想回應一句:「因為你生得太醜。」
但這就是事實的全部嗎?我隱約覺得不對。
和歷史悠久的神主牌 (註:神主牌這詞
就是這篇文章令電腦小氣
How many bits of information are in a password?
The number of bits of information in a password are a function of thealphabet that the password is drawn from and how many characters longit is. The formula is:
nbits = ceil(log2(len(alphabet)) * nchars)
So what does that mean? Let's take the case of 8 character longUnix passwords, and do a table:
| alphabet | total bits | (bits per character) |
| lower case ASCII | 38 | 4.7 |
| lower case plus digits | 42 | 5.2 |
| upper and lower |
How not to set up your DNS (part 16)
Sort of presented in the traditional illustrated format:
; sdig ns ibc.com.au.ns1.ibc.com.au.ns2.ibc.com.au.; dig cname ibc.com.au. @ns1.ibc.com.au.[...];; flags: qr aa; QUERY: 1, ANSWER: 1, [...][...];; ANSWER SECTION:ibc.com.au. IN SOA ns1
遊樂場在哪裡
從未在中環正式上班,但這個地方,是我的生活重心,是我回憶中的場景,是我的遊樂場。
小至買零食高跟鞋打掌購物吃飯看戲clubbing約會到學生年代的兼職曾經遇上的男人有發生過的愛情,