SELECT * FROM 成績單 LIMIT 3 // 取成績單前三筆資料
SELECT * FROM 成績單 ORDER BY 分數 DESC LIMIT 3 // 取分數前三名的資料
SELECT * FROM 成績單 ORDER BY 分數 DESC LIMIT 3, 7 // 取第四名到第十名的資料
分頁查詢
隨著查詢筆數越來越多,網站可能就會需要用分頁來表示查詢結果。
這裡會出現一個問題 Offset ( LIMIT 的第1個參數 ) 越大,查詢速度越慢。
SELECT * FROM 成績單 LIMIT 100000, 1 // 大 Offset
Google 的結果是 InnoDB 會有的情況,InnoDB 會掃 100001 筆資料,然會再把 100000 筆資料給捨棄,導致查詢速度越來越慢。所以解決方法為先只掃索引。
SELECT * FROM 成績單 WHERE id >= (SELECT id FROM 成績單 LIMIT 100000, 1) LIMIT 1
Don't lie, I know you've been thinking it 別說謊了,我知道你一直很渴望 And two times, you let it slip from your lips 兩次了,你那不想讓人聽見的低語 You've got too much pride to make any promises 你有太多不必要的驕傲以致做不出任何承諾 Thinking that we got time, and you want to keep it in 覺得我們還有時間,想著先保留 I want you out in the pouring rain 想要你在傾盆大雨中 I want you down on your knees 想要你跪下雙膝 Prayin' to God that I feel the same 祈禱著我跟你一樣愛著彼此 I'm right here, baby, so please 我就在這寶貝,所以請 Hold me up, tie me down 抱起我,綁住我 'Cause I never wanna leave your side 因為我永遠不想離開你 Swear to never let you down 發誓永遠不會讓你失望 And it's been eatin' me alive 這份想法正把我身吞活剝 You can take me home 你可以把我帶回家 You can never let me go 你也可以讓我永遠不離開 Hold me up, hold me up 所以抱起我,抱起我 And tie me, tie me down, down (down) And tie me, tie me down, down And tie me, tie me down, down (down) And tie me, tie me down, down 綁住我 Nine lives until you fall at my feet 不顧一切直到你倒在我腳下 Don't hide, you're wasting your energy 別躲了,你是在浪費力氣 You're not shy, so baby, it's useless 你又不害羞,所以寶貝別躲了 So don't try, 'cause you'll end up losin' it 別再嘗試了,最後也只會敗在我手下 Hold me up, tie me down 抱起我,綁住我 'Cause I never wanna leave your side 因為我永遠不想離開你 Swear to never let you down 發誓永遠不會讓你失望 And it's been eatin' me alive 這份想法正把我身吞活剝 You can take me home 你可以把我帶回家 You can never let me go 你也可以讓我永遠不離開 Hold me up, hold me up 所以抱起我,抱起我 And tie me, tie me down, down (down) And tie me, tie me down, down And tie me, tie me down, down (down) And tie me, tie me down, down 綁住我 So wrap your arms around my chest 用你的手抱住我吧 And I'll put my hands around your neck 我也會用我的抱住你的 'Cause nobody wins these waiting games 這場等待的遊戲是不會有贏家的 You push and you pull, but you should stay 你一下推又一下拉的,但你真正該做的是留下 Stay 留下
Nine lives - Myth to typically describe cats or humans that survive shit that should have otherwise killed them. Narrowly escaping death time after time.
import unittest
class TestStringMunittestethods(unittest.TestCase):
def test_upper(self):
self.assertEqual('foo'.upper(), 'FOO')
def test_isupper(self):
self.assertTrue('FOO'.isupper())
self.assertFalse('Foo'.isupper())
def test_split(self):
s = 'hello world'
self.assertEqual(s.split(), ['hello', 'world'])
# check that s.split fails when the separator is not a string
with self.assertRaises(TypeError):
s.split(2)
if __name__ == '__main__':
unittest.main()
unittest.main() 會執行所有 test_ 開頭的 function,主要判斷的 function 是 assert
assertEqual - 確認是否符合期望的值
assertTrue、assertFalse - 確認是否符合期望的判斷
assertRaise - 確認是否有特定 exception raise
接著就是執行以上這 python 檔
D:\temp\JunYe\MyPython\Python3\LeetCode\UnitTest>python3 UnitTest.py
...
----------------------------------------------------------------------
Ran 3 tests in 0.001s
OK
D:\temp\JunYe\MyPython\Python3\LeetCode\UnitTest>
>>> d = {}
>>> d['a']
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyError: 'a'
這時就要靠 collections.defaultdict(default_factory)
>>> from collections import defaultdict
>>> d = defaultdict(int)
>>> d['a']
0
再回到檢查 dictionary 是否存在索引值的地方
from collections import defaultdict
s = 'mississippi'
my_dict = defaultdict(int)
for key in s:
if key in my_dict:
my_dict[key] += 1
else:
my_dict[key] = 1
print(my_dict)
No more lazy mornings with you lyin' next to me 再也沒有那些你躺在我身旁的慵懶早晨 No more late night talkin' 'fore we lay our heads to sleep 再也沒有那些晚上入睡前的談話 No more lookin' in the mirror with you steppin' on my feet 再也沒有那些你踩著我的腳照著鏡子的場景 Without your arms around my shoulders 你環繞在我肩膀的手已然消失 I've lost the strength to be 我失去了力氣 Come and set me free 解救我吧 Will you stay with me tonight 你今晚會陪伴我嗎 ? And pretend it's all alright? 假裝一切沒事 Tell me that you love me 告訴我你愛我 The way you used to love me 就像以前一樣地愛我 Will you whisper in my ear 你會在我耳邊說出 Those three words I wanna hear? 那個我想聽到的三個字嗎 ? Tell me that you love me 告訴我你愛我 The way you used to love me 就像以前一樣地愛我 Even if you don't mean it will you say I'm still the one 你會說我仍然是你的唯一嗎 ? 即使你不是真心的 Hide the way that you're feeling and make believe I still belong 把感情藏起來讓我相信我還是屬於你的 And nothing's changed since you've gone 就跟你離開前一模一樣
下面拿一題示範 0947 - Most Stones Removed with Same Row or Column
class Solution:
def removeStones(self, stones: List[List[int]]) -> int:
# 想像用 垂直線 跟 水平線 去想辦法連接所有石頭
# 連接了 n 個, 代表可以去掉 n -1, 看圖
# 初始樹的數目 以及 複製一個 stones 去做 DFS
treeNum = 0
points = {(i, j) for i, j in stones}
# 建立 row 跟 col 兩個 List
# row 紀錄該 index 下的所有有石頭的 y 座標值
# col 紀錄該 index 下的所有有石頭的 x 座標值
row = collections.defaultdict(list)
col = collections.defaultdict(list)
for i, j in stones:
row[i].append(j)
col[j].append(i)
for i, j in stones:
if (i, j) in points:
self.dfs(i, j, row, col, points)
treeNum += 1
return len(stones) - treeNum
def dfs(self, x, y, row, col, points):
# 刪除這個點
points.discard((x, y))
# 此兩個刪除是為了加速計算
#row[x].remove(y)
#col[y].remove(x)
for i in row[x]:
if (x, i) in points:
self.dfs(x, i, row, col, points)
for i in col[y]:
if (i, y) in points:
self.dfs(i, y, row, col, points)
以 C 的角度來看 points 不是全域變數根本不可能有用,但在 python 卻成功了
因為在 dfs() 這 function 裡的 points,若沒有特別賦予值的話,就是一個指標指到 call function 所傳入的變數
火箭總管 Morey 在 2019/10/5 在 Twitter 上轉發了 Fight For Freedom. Stand with Hong Kong.
老實說那就是一張圖,而且很快就刪推,加上NBA火箭隊的中國球迷最多,很難想像 Morey 是在深思熟慮後發推,我猜想不經過思考就發的推機率很高。
If you want my love 想要得到我的愛 He gotta do what he does 必須要做該做的事 If you want these sweet like sugar Gucci lips 想要得到我甜蜜的Gucci紅脣 He gotta give it up 必須得先放棄 I know you think I'm cool 我知道你覺得我很酷 But I ain't one of the boys 但我是不屬於"男孩"的 No, don't be scared that I'm gon' tie you down 不用擔心我把你綁住 I need a little more 我只是需要更多 Baby, don't call me your friend 寶貝,不要說我是你朋友 If I hear that word again 如果我再聽到一次 You might never get a chance to see me naked in your bed 你很可能再也看不到我裸體在你床上 And I know girls ain't hard to find 我也知道女孩到處都是 But if you think you wanna try 但如果你想試試 Then consider this an invitation to kiss my ass goodbye 就當作是"拜拜"的邀請函吧 Give me that title, title 給我那個名稱吧 Come on give me that title, title 快叫我那個名稱吧 Better give me that title, title 最好給我那名稱喔 Come on give me that title, title 快叫我那個名稱吧 If it ain't no thang 如果沒有什麼 I won't be hanging around 我才不會這裡瞎耗著 But don't blow up my shit at 3 AM saying 但別半夜三點打給我 "How you need me now?" 說你需要我 Don't call me boo 別叫我"寶貝"(一種寶貝叫法) Like you're some kind of ghost (which you're a ghost) 好像你是鬼一樣(但你的確像鬼一樣)(守護靈或糾纏不清) If you don't want me seeking other guys 如果你不想我去找其他男人 Well, here's what you need to know 你必須先知道這些
Yeah, said I'm a special kind of woman 對,說過我是特別的女人 I'm loving what you got, but I'm hating what you doing 我喜歡你,但我討厭你現在做的事 Gotta understand that I'm looking for a man 必須知道我在找一個男人 Who can get up on a bike, look ma, no hands 一個有擔當的男人(就是一個情景證明不是男孩而已) You gotta show me off, off 你至少要演給我看 But you embarrassed, if that's the case I'm all gone 如果你覺得不好意思,只好說掰掰 You gotta treat me like a trophy, put me on the shelf 你要向像對待獎盃一樣對待我,把我保護得好好的 Or call something else 或其他東西(這裡指像獎盃會珍惜的東西)
Gonna get in your mind, one fine day 總會有一天,讓我進入你腦海 Gonna figure you out, one fine day 總會有一天,讓我看透你 Dear Lord, maybe I should stay away, stay away 神啊,也許我該離遠點 Little lost, little blind, blind with temptation 一點迷失,一點盲目,在誘惑裡失去方向 Tell me something, do I make you feel the way that I do? 告訴我,要如何讓你感受到我所感受到的 I been uptight, you got me right, I'm back into my groove 當我不能放鬆時,你總能察覺,讓我回到正軌 Keep me bumpin', give me something that I could get used to 讓我感受,讓我有東西去成癮 I'm a fire, gotta keep me lit all night, all night, they say 我就像火焰,必須讓我的熱情燃燒整個晚上 And they say my heart will bleed 人們總說有一天我會受傷 But it doesn't matter to me 但我一點都不在意 'Cause your love is so nasty 因為你的愛實在是太下流了 Boy, yeah yeah yeah ... In the dark, I'm living the dream 夜幕低垂,我活在夢裡 When you pull up behind me 當你在後面威脅著我 Like a mixer of night cream 就像攪拌器,攪拌著屬於夜晚的奶油(為我的處男翻譯道歉...) Boy, yeah yeah yeah ... Every night, club tights, touch your face 每個夜晚,每件緊身褲,每次撫摸你的臉 Every night I try to find out what's on your brain 每個晚上都試著看透你 Dear Mama, help me know just what to say 聖母阿,讓我知道該說什麼吧 'Cause I don't wanna be blind with temptation 因為我不想迷失在誘惑裡
You got me late night talking, I come over 你讓我夜晚輾轉難眠,我過來了 But you won't replay in my mind, all slumber 因為在夢裡你不會出現 I'm wide awake, my body shakes and shivers 十分清醒,身體微微顫抖著 I'm a fool, I guess 'cause I text you yes 我一定是笨蛋,因為我又答應妳了 Even though my friends, they say 即使我的朋友他們說...
lit : When something is turned up or popping ...
只是偶然聽到,沒想到這麼A...