Every Second Counts in HKDSE
Paper 1 is 105 minutes. These shortcuts shave seconds off every question.
1. Swap Variables in One Line
# Long way (using temp) temp = a a = b b = temp # Short way a, b = b, a
2. Multiple Assignment
# Assign same value x = y = z = 0 # Assign different values name, age, school = "Chan", 17, "Victoria"
3. Chained Comparisons
# Instead of: if x > 0 and x < 10: # Use: if 0 < x < 10:
4. Ternary If
# Instead of 4 lines:
if score >= 50:
status = "pass"
else:
status = "fail"
# Use 1 line:
status = "pass" if score >= 50 else "fail"
5. String Multiplication
# Instead of a loop:
line = "-" * 30
# "------------------------------"
# Print headers instantly
print("=" * 20)
print("REPORT")
print("=" * 20)
6. List of Zeros
# Instead of a loop: zeros = [0] * 10 # [0,0,0,0,0,0,0,0,0,0] # 2D list of zeros grid = [[0] * 3 for _ in range(3)]
7. enumerate for Index+Value
# Instead of:
i = 0
for item in lst:
print(i, item)
i += 1
# Use:
for i, item in enumerate(lst):
print(i, item)
8. sum() With Condition
# Count pass scores passes = sum(1 for s in scores if s >= 50) # equivalent to: len([s for s in scores if s >= 50])
9. Min/Max with key
students = [("Chan", 85), ("Lee", 72)]
top = max(students, key=lambda x: x[1])
# ("Chan", 85)
10. Unpacking in Function Calls
lst = [1, 2, 3] print(*lst) # 1 2 3 (unpacked) print(*"HKDSE", sep="-") # H-K-D-S-E
Bonus: Input Multiple Numbers
# Instead of 3 lines: a = int(input()) b = int(input()) c = int(input()) # Use: a, b, c = map(int, input().split())
Drill These in PyForm
Memorise by writing each shortcut 5 times in PyForm. Muscle memory kicks in during exams.
Practise Now โ