>>> 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...