搜尋此網誌

2026年5月12日星期二

Tuples and Sets in Python

In Python, sets and indexes are two different concepts, and they don’t work together the way lists or tuples do.

The error 'set' object is not subscriptable means you tried to access a set element by index, like this:

mySet = {'a', 'b', 'c'}

print(mySet[0])   # ❌ Error

Subscriptable means you can use square brackets [] to access elements by position (like lists, tuples, strings).

Sets are unordered collections → they don’t have positions or indices.

That’s why Python raises this error.


Defined with curly braces {} or the set() constructor.

mySet = set(('a', 'b', 'c'))

('a', 'b', 'c') → This is a tuple containing three elements.

set(('a', 'b', 'c')) → The set() constructor takes that tuple and converts it into a set.

Result: {'a', 'b', 'c'}

Sets automatically remove duplicates (though here there aren’t any).

mySet now holds a set with the elements 'a', 'b', 'c'.


myList = ['a', 'b', 'b', 'c', 'c'] myList = list(set(myList)) print(myList)

['a', 'b', 'b', 'c', 'c'] → a list with duplicates.

set(myList) → converts the list into a set, automatically removing duplicate

list(set(myList)) → converts the set back into a list

Output: ['a', 'b', 'c']

But the order may vary, e.g. ['b', 'c', 'a'].


mySet.add('d') inserts the element 'd' into the set.

If 'd' was already inside, nothing changes (sets don’t allow duplicates).


while len(mySet):

    print(mySet.pop())

Condition: while len(mySet):

The loop runs as long as the set is not empty (len(mySet) > 0).

Inside the loop:

mySet.pop() removes and returns an arbitrary element from the set.

print() displays that element.

Iteration:

Each loop removes one element until the set becomes empty.

Loop ends when len(mySet) == 0.

The order is not guaranteed because sets are unordered. Running the same code again may give a different sequence.

myList = ['a', 'b', 'c'] print(myList.pop()) # 'c' (last element) print(myList.pop(0)) # 'a' (index 0) print(myList) # ['b']

mySet = {'a', 'b', 'c'}
mySet.discard('a') print(mySet)

mySet.remove('a') → removes 'a', but raises an error if 'a' is not found. mySet.discard('a') → removes 'a' if present, but does nothing if not found (safer).


def returnsMultipleValues(): return 1, 2, 3 print(type(returnsMultipleValues()))

return 1, 2, 3 → In Python, when you separate values with commas, they are automatically packed into a tuple.

Equivalent to: return (1, 2, 3)
So the function returns (1, 2, 3).
type(returnsMultipleValues()) → This checks the type of the returned object.

Output: <class 'tuple'>

a, b, c = returnsMultipleValues()

returnsMultipleValues() returns a tuple (1, 2, 3).

Python then unpacks that tuple into the three variables:
a = 1
b = 2
c = 3

Unpacking variables in Python means taking a collection (tuple, list, set, dict, etc.) and assigning its elements to multiple variables at once.

Microsoft Copilot

白平衡 (White Balance)

Daylight and Cloudy white balance settings differ mainly in color temperature. Daylight is optimized for clear, sunny conditions with direct sunlight, while Cloudy compensates for overcast skies.

overcast: covered with clouds; not bright

Key Differences:

Daylight targets around 5000-5500K, producing neutral tones for bright, overhead sun; it can make cloudy scenes look cooler or bluish.

Cloudy uses 6000-6500K (or higher), adding warmth (yellow/orange tones) to counteract the diffused, cooler light from clouds. It's good for Hong Kong’s cloudy spring weather.

Use Daylight for sunny outdoor shots; switch to Cloudy on overcast days to avoid flat, cold colors.

日光與陰天白平衡設定主要在色溫上有所不同。日光模式適合晴朗、陽光直射的環境,而陰天模式則用來補償多雲天氣。

主要差異:

日光模式:目標色溫約 5000–5500K,在明亮的正午陽光下呈現中性色調;但在陰天場景中可能會顯得偏冷或帶藍色。

陰天模式:使用 6000–6500K(或更高),增加暖色調(黃色/橙色),以抵消雲層散射造成的冷色光。這在香港春季多雲天氣特別適合。

實用建議:晴朗的戶外拍攝使用日光模式;在陰天時切換到陰天模式,避免照片顏色顯得平淡、冷調。

Aperture Priority, ISO 200, 35mm, f/9, 1/200s

White Balance: Cloudy (Warmer)

White Balance: Daylight (Cooler)

Information: Perplexity.AI, Microsoft Copilot, www.oxfordlearnersdictionaries.com

2026年5月11日星期一

Preparation before purchasing iPhone 17

Both iPhone 17 and 17 Pro now feature a 120Hz ProMotion display for smooth scrolling. The standard 17 lacks a dedicated zoom lens, relying on a 2x "optical quality" crop from its main sensor. Both have the new Ceramic Shield 2 (3x more scratch-resistant) on the front, but only the Pro model features it on the back as well.

Whether 8GB of RAM is a "disadvantage" depends largely on how long you intend to keep the phone and how heavily you use multitasking features. In the current generation of mobile tech, 8GB is the baseline for modern "Intelligence" features. Apple has optimized its software so that 8GB can handle complex tasks like local image generation and text summarization.

Given that you are currently using an iPhone SE2 with only 60GB used and plan to keep the iPhone 17 for more than three years, here is a breakdown of why 256GB is likely your "sweet spot," while 512GB is a luxury choice. If you use iCloud (even the 50GB or 200GB plans), your local storage needs drop significantly as older photos are offloaded to the cloud.

iPhone 17 256GB: HKD 6,899

iPhone 17 512GB: HKD 8,599

Your current 50GB iCloud plan is only 20% used (~10GB), so no upgrade needed after getting the iPhone 17—it'll comfortably last 3+ years with your 256GB phone choice.

Activating an eSIM for iPhone 17 with CMHK (China Mobile Hong Kong) typically takes 5-15 minutes, depending on whether you do it online or in-store.

Skipping Trade In means you'll pay full price for iPhone 17 256GB at Apple Store Canton Road, but the process stays identical.

Apple Store Canton Road (100 Canton Rd, open till 10pm): Buy iPhone 17, data transfer from SE2, setup iCloud 50GB → 15 mins

Walk 10 mins to CMHK Mong Kok (2J Sai Yeung Choi St S): Show HKID → get eSIM QR code → scan & activate → 5-15 mins

SE2 stays with you (continue using 60GB photos there or factory reset later)

The iPhone 17 series supports 40W wired fast charging with a compatible USB-C charger, reaching 50% battery in about 20 minutes.

STUDIO A (Apple Premium Reseller)

2197D, 2/F tmtplaza Phase 1

Mon - Thu: 11:00am - 08:00pm

Fri - Sun, PH: 12:00pm - 09:00pm

2026年5月7日星期四

Notebook

Device Using: Lenovo ThinkPad X280
Processor: Intel® Core™ i5-8250U CPU @ 1.60GHz (1.80 GHz)
4 Cores, 6 MB Smart Cache
Operation System: Windows 11 Home
Installed RAM: 8.00 GB (7.85 GB usable)
Graphics Card: Intel(R) UHD Graphics 620 (128 MB)
Storage: 121 GB of 238 GB used
System Type: 64-bit operating system, x64-based processor
Display Size: Size: 12.5 inches (diagonal)
No pen or touch input is available for this display

Latest Device: Lenovo ThinkPad X13 Gen 6
Intel® Core™ Ultra 5 225U Processor
12 Cores, E-cores up to 3.80 GHz P-cores up to 4.80 GHz
A customizable option for SMBs or professionals seeking flexibility
Ideal for lighter tasks and budget-conscious users
Operation System: Windows 11 Pro 64
Memory: 16 GB LPDDR5X-8533MT/s (Soldered)
Storage: 512 GB SSD M.2 2280 PCIe Gen4 TLC Opal
Display: 13.3″ WUXGA (1920×1200) IPS, 400 nits, anti‑glare, 100% sRGB

2026年5月6日星期三

Lists in Python

In Python, list slicing lets you extract portions of a list using the syntax:

list[start:stop:step]

Components

  • start → index where the slice begins (inclusive).

  • stop → index where the slice ends (exclusive).

  • step → interval between indices (default is 1).

numbers = [10, 20, 30, 40, 50, 60] print(numbers[1:4]) # [20, 30, 40] (from index 1 to 3) print(numbers[:3]) # [10, 20, 30] (first 3 elements) print(numbers[3:]) # [40, 50, 60] (from index 3 to end) print(numbers[::2]) # [10, 30, 50] (every 2nd element) print(numbers[::-1]) # [60, 50, 40, 30, 20, 10] (reversed list)

numbers[1:4]
  • Start = 1 → begin at index 1 (the second element, which is 20).

  • Stop = 4 → go up to, but not including, index 4.

  • So you get elements at indices 1, 2, and 320, 30, 40.

Python slicing always excludes the stop index. That’s why 50 (at index 4) isn’t included.

print(numbers[::2])

  • Start = empty → defaults to the beginning of the list (index 0).

  • Stop = empty → defaults to the end of the list.

  • Step = 2 → take every second element.

So Python picks indices 0, 2, 4, ... until the end

myList = [1, 2, 3, 4, 5] print(myList[0:6:2])

Start = 0 → begin at index 0 (1).

Stop = 6 → go up to, but not including, index 6.

Step = 2 → take every second element.

Notice that even though you wrote stop = 6, your list only goes up to index 4. Python slicing doesn’t throw an error — it just stops at the end of the list. That’s why you still get [1, 3, 5].

The range() function in Python generates a sequence of integers, starting from a given start (default 0), stopping before a given stop, and incrementing by a given step (default 1). It’s most often used in loops to control iteration.

range(start, stop, step)

start → optional, default 0. First number in the sequence.

stop → required. Sequence ends before this number.

step → optional, default 1. Difference between consecutive numbers.

Range function is immutable.

>>> for i in range(5): ...     print(i) ... 0 1 2 3 4 >>>

>>> myList = [1,2,3,4] ... myList.append(5) ... print(myList) ... [1, 2, 3, 4, 5] >>>

In Python, lists have several useful methods for adding and removing elements. Let’s look at insert(), remove(), and pop() side by side:

numbers = [10, 20, 30] numbers.insert(1, 15) # insert 15 at index 1 print(numbers) # [10, 15, 20, 30]

numbers = [10, 20, 30, 20] numbers.remove(20) # removes the first 20 print(numbers) # [10, 30, 20]

pop(): remove and return an element at a given index (default is the last element).

>>> myList = [1,2,3,4,5]
>>> myList.pop()
5

numbers = [10, 20, 30] x = numbers.pop(1) # removes element at index 1 print(x) # 20 print(numbers) # [10, 30]

>>> myList = [1,2,3,4,5]
... while len(myList):
...     print(myList.pop())
...
5
4
3
2
1

Loop ends because len(myList) is now 0.

>>> a = [1,2,3,4,5]
... b = a.copy()
... a.append(6)
... print(a)
... print(b)
...
[1, 2, 3, 4, 5, 6]
[1, 2, 3, 4, 5]

b = a.copy() → makes a shallow copy of a.

  • Now b has its own separate list [1,2,3,4,5].

Microsoft Copilot

White Balance

Auto (White Priority): best for indoor fluorescent or mixed light

Shade: adds warmth to counter bluish tones

Cloudy: warmer balance, good for HK’s cloudy spring weather

Tungsten Light: best for indoor with incandescent bulbs

White Fluorescent Light: best for offices, malls in HK

Microsoft Copilot

Personal Computer

Albuquerque: city (the state's most populous) in central New Mexico population 545,852

makeshift: used temporarily for a particular purpose because the real thing is not available

plywood: board made by sticking thin layers of wood on top of each other

The Altair 8800, introduced by MITS in January 1975, is widely recognized as the first commercially successful personal computer, igniting the microcomputer revolution.

laundromat: ​​a place where you can wash and dry your clothes in machines that you pay to use

massage parlor: a place where you can pay to have a massage

shell out: ​(informal) to pay a lot of money for something

novelty: the quality of being new, different and interesting

splurge: an act of spending a lot of money on something that you do not really need

gadget: a small tool or device that does something useful

tinker: tinker (with something) to make small changes to something in order to repair or improve it, especially in a way that may not be helpful

Menlo Park: city in western California southeast of San Francisco population 32,026

swap: to give something to somebody and receive something in exchange

glimpse: a sight of somebody/something for a very short time, when you do not see the person or thing completely

toggle: to press a key or set of keys on a computer keyboard in order to turn a feature on or off, or to move from one program, etc. to another

staccato: (music, from Italian) with each note played separately in order to produce short, sharp sounds

rendition: the performance of something, especially a song or piece of music; the particular way in which it is performed

2001: A Space Odyssey is a seminal 1968 science fiction film directed by Stanley Kubrick and co-written with Arthur C. Clarke.

home brew: beer that somebody makes at home

stoke something (up) to make something increase or develop more quickly

whistle-stop: visiting a lot of different places in a very short time

counterculture: a way of life and set of ideas that are opposed to those accepted by most of society; a group of people who share such a way of life and such ideas

hippie: a person who rejects the way that most people live in Western society, often having long hair, wearing brightly colored clothes and taking illegal drugs. The hippie movement was most popular in the 1960s.

zeitgeist: the general mood or quality of a particular period of history, as shown by the ideas, beliefs, etc. common at the time

monolithic: ​(often disapproving) used to describe single, very large organizations that are very slow to change and not interested in individual people

Lockheed Martin (NYSE: LMT) is the world's largest defense and aerospace corporation

inaugural: IPA[ɪˈnɔːgjʊrəl]


Bill Gates "Source Code"

Online Dictionaries Used:

hk.dictionary.search.yahoo.com

www.oxfordlearnersdictionaries.com

www.merriam-webster.com

Google AI Overview