搜尋此網誌

2026年6月10日星期三

Chapter Quiz

In Python, a defaultdict is a special kind of dictionary from the collections module. Its main advantage is that it automatically provides a default value for any key that doesn’t exist yet, instead of raising a KeyError.

You create it by passing in a default factory function (like int, list, or set).

When you access a missing key, defaultdict calls that factory to create a default value and stores it under that key.

In Python, the get() function is a method of dictionaries. It’s used to safely retrieve the value for a given key without risking a KeyError if the key doesn’t exist.


In Python, a set is a built‑in data type that represents an unordered collection of unique elements. Think of it like a mathematical set: no duplicates, and order doesn’t matter.

Unique elements only → duplicates are automatically removed.

Unordered → items don’t have a fixed position or index.

Mutable → you can add or remove elements.

Fast membership tests → checking if something is in a set is very efficient.

# Using curly braces fruits = {"apple", "banana", "cherry"} # Using the set() constructor numbers = set([1, 2, 2, 3]) print(numbers) # {1, 2, 3} (duplicates removed)


In Python, item[1:3] is an example of list slicing (or sequence slicing).

item is assumed to be a list (or another sequence like a string or tuple).

[1:3] means:

    Start at index 1 (the second element, since Python uses zero‑based indexing).

    Stop before index 3 (so it includes elements at positions 1 and 2, but not 3).

In Python, item[1:] is another example of slicing.

1: means start at index 1 (the second element, since indexing starts at 0).

The colon without an end index means go all the way to the end.

So item[1:] returns everything from index 1 onward.


A nested list comprehension in Python is simply a list comprehension inside another one. It’s often used to flatten lists, generate combinations, or apply transformations across multiple levels of data.

[expression for outer in iterable1 for inner in iterable2]

The outer loop runs first, then the inner loop.

You can nest more than two loops if needed.

To apply a function someFunc to all comments in a list of blog objects using a nested list comprehension

[[someFunc(comment) for comment in blog.comments] for blog in blogs]

Outer loopfor blog in blogs → iterate through each blog object.

Inner loopfor comment in blog.comments → iterate through each comment in that blog.

ExpressionsomeFunc(comment) → apply your function to each comment.

Result → a list of lists, where each inner list contains the processed comments for one blog.

def someFunc(text): return text.upper() class Blog: def __init__(self, comments): self.comments = comments blogs = [ Blog(["Nice post!", "Great read"]), Blog(["Interesting idea", "Could be improved"]), Blog(["Loved it", "Thanks for sharing"]) ] processed = [[someFunc(comment) for comment in blog.comments] for blog in blogs] print(processed)

Result:
[['NICE POST!', 'GREAT READ'], ['INTERESTING IDEA', 'COULD BE IMPROVED'], ['LOVED IT', 'THANKS FOR SHARING']]

  • __init__ → the special method that runs automatically when you create a new object from the class.

  • self → refers to the new object being created.

  • comments → a parameter you pass in when creating the object.

  • self.comments = comments → stores the passed‑in value as an attribute of the object, so you can access it later.

class Blog: def __init__(self, comments): self.comments = comments # Create a Blog object with a list of comments blog1 = Blog(["Nice post!", "Great read"]) print(blog1.comments) # ['Nice post!', 'Great read']

  • When you call Blog(["Nice post!", "Great read"]), Python automatically calls __init__.

  • The comments list is passed in and stored as self.comments.

  • Now the object blog1 has an attribute comments you can use anywhere.


list(range(101))[::5]

range(101) → generates numbers from 0 up to 100 (inclusive).

So list(range(101)) = [0, 1, 2, 3, ..., 100].

[::5] → slice syntax with:

start = empty → defaults to beginning (0).

stop = empty → defaults to end (100).

step = 5 → take every 5th element.

Result → all multiples of 5 between 0 and 100.


list(range(101))[::-5]

Step 1: Build the list

list(range(101)) → [0, 1, 2, 3, ..., 100]

Step 2: Understand the slice

The slice is [::-5], which means:

start → empty → defaults to the end of the list.

stop → empty → defaults to the beginning.

step = -5 → move backwards, taking every 5th element.


Microsoft Copilot

Cons of social media

William James said, "Our life experience will equal what we have paid attention to, whether by choice or by default."

我們的人生經驗,將等同於我們所注意到的事物,無論是出於選擇還是無意之中。

我們所注意到的事物不只是外在事件,也包括我們的想法、情緒、人際互動、習慣與重複的觀察。換句話說,注意力決定了哪些事物被放大、被記住、被內化。

如果你經常刻意練習感恩、關注身邊的美好,你的生活經驗會偏向正面與滿足。如果你習慣性地沉迷於負面新聞或無止境的社群媒體滾動,即使沒有刻意選擇,你的人生感受也會變得焦慮或空虛。

注意力就是資源:有意識地選擇把注意力放在哪裡,就能改變你未來的回憶與感受。
管理環境與習慣:減少無意的干擾,建立有意的練習(如專注、閱讀、深度交流),能讓人生經驗更符合你想要的樣子。

Microsoft Copilot

Nicole Vignola "Rewire"

Part II of Python Test

def decodeString(encodedList):
    decodedStr = ''
    for item in encodedList:
        decodedStr = decodedStr + item[0] * item[1]
    return decodedStr

1. Start with an empty string: decodedStr = ''

2. Loop through each (char, count) tuple in encodedList.

3. Multiply the character by its count:

item[0] * item[1]

Example: 'a' * 3 → "aaa".

4. Concatenate to decodedStr.

5. Return the final reconstructed string.

Microsoft Copilot

Be water

如水柔順,如水堅強,方可如水無孔不入、無堅不摧。

在人際關係中,要懂得柔軟、包容。

在挑戰困境時,要保持堅毅、持續。

在策略上,要懂得靈活變通,找到突破口。

Boss without insight

outlier: a person or thing that is different from or in a position away from others in the group

brim: to be full of something

underscore: ​to emphasize or show that something is important or true

chalk up: ​(informal) to achieve or record a success, points in a game, etc.

to trip over something: to fall over, to stumble on, to slip on something

spill out: ​to tell somebody all about a problem etc. very quickly; to come out quickly

goad: ​to keep annoying somebody/something until they react

scrap something: to cancel or get rid of something that is no longer practical or useful

cotton candy: ​a type of sweet in the form of a mass of sticky threads made from melted sugar and served on a stick, especially at fairgrounds

if a computer crashes or you crash a computer, it stops working suddenly

spawn: to cause something to develop or be produced

rightfully: according to the law or to what is right or correct

flawed: having a flaw; not perfect or correct

horde: a large crowd of people

boomerang: if a plan boomerangs on somebody, it hurts them instead of the person it was intended to hurt

Bill Gates "Source Code"

Online Dictionaries Used:

hk.dictionary.search.yahoo.com

www.oxfordlearnersdictionaries.com

2026年6月9日星期二

對人的工作

大主管將我投閒置散,我這個小主管怎都要做一些事情。內地姐姐離職,樓下 Pop-up Store 工作環境有改善,正是時機。天下武功,唯快不破。小朋友不明白我便解釋給他聽。小朋友問我為什麼不私下與大主管商討人手安排,而選擇一開始便在群組提議,認為我以下犯上,架空權力。可是,小朋友沒有想到私下商討失敗了,再在群組反抗會有什麼後果。區經叫我和大主管多溝通,面對面是行不通的,因為大主管經常扮失憶,要用文字溝通,要有根有據。區經說 Pop-up stores 可交給彩虹姐姐 Run, 叫我多專注主舖的工作。在群組提議了,就算大主管沒有接納,區經都知道發生什麼事。題外話,大主管放假的時候會吩咐我做一些工作。上班要完成上司給我的工作十分正常,但問題是大主管會遙控彩虹姐姐,監察我的工作情況。被監察的我,一點也不好受。對著時常設陷阱的主管,對人的工作,心很累。

2026年6月8日星期一

"Haven't"〈Yoasobi feat. Lee Suhyun〉


連淚水都沒流下
度過的日子連一絲痕跡也沒留下
 「再見了」

一個獨自迎接的早晨
迴響著某個人的聲音
在兩人曾一同度過的房間裡
依然閉著雙眼思索

犯錯的是誰?
我不知道啊
誰都沒有錯吧!
或許

我們不論經歷多少次
對,不論過了多少年也必定
都只會隨著「再見」而畫上句號
這也是沒辦法吧 一定
「歡迎回家」
不經意脫口而出的這句話
感覺不對吧

一個獨自迎接的早晨
忽然想起某個人的事
兩人一同度過的日子裡
理所當然地殘留著

犯錯的是你
是這樣嗎?
犯錯的是我
或許吧!

這也就是世俗平庸的戀愛吧
那便是最終的答案了
我們漸漸地產生了分歧
這也不過是常有的、聽慣了的故事罷
就連那般閃耀著光芒的日子
也終究會蓋滿灰塵

我們不論經歷多少次
對,不論過了多少年也必定
都會走向「再見」的道路
這也是沒辦法吧 一定
「歡迎回家」
像往常一樣 衝出了口

無法互相理解的事
不論多少一定會有吧
畢竟我們不可能包容彼此的所有
然而,要是你感覺到那些溫柔的日子
漸漸變成痛苦的日子的話
那就再也回不去了

我們不論經歷多少次
我們不論經歷多少次
不論過了多少年也必定
都只會隨著「再見」而畫上句號
這也是沒辦法的吧 一定
「歡迎回家」
不經意脫口而出的這句話
感覺不對吧

即使如此 不論經歷多少次
對,不論過了多少年也必定
如果還能回到最初的話……
不禁產生了這樣的想法
「歡迎回家」
對這句無法傳達的話語
露出了苦笑
是一個有些寒冷的早晨