2024年12月8日 星期日

. .燕俠語錄 20241208:「[通靈之術] 職場溝通問題為什麼會出現?1. 經驗不足 2. 能力不行 3. 原則性不強 4. 粗心大意」--- 墨者燕俠(劉建春)

2024年12月7日 星期六

. .燕俠語錄 20241207:「上善若水」--- 墨者燕俠(劉建春)


「上善若水」:最善良的人有如水的品德。

老子〔道德經〕第八章:「上善若水。水善利萬物而不爭,處眾人之所惡,故幾於道。」

老子以水喻有德行的人,因為水有三項特性:
一是滋養萬物,利益眾生;
二是柔順無形,不與人爭;
三是就下而流,低卑自處。

這是指水是
滋潤萬物的雨露,
是川流不息的溪河,
是容納百川的大海,
而不是淹滅生靈的洪水暴雨,海嘯狂濤。可說是老子選擇性的審美觀點,以水性柔順、就下、利萬物來比喻有美德的人。

2024年11月25日 星期一

.燕俠語錄 20241125:「在這個世界上,最偉大的成就並非那些永遠立於不敗之地的人;而是那些跌倒之後 能夠再爬起來的人。」--- 墨者燕俠(劉建春)

2024年11月23日 星期六

.燕俠語錄 20241123:「只有做不做,沒有能不能,只要我去做了,終有一天必定成功。」--- 墨者燕俠(劉建春)

2024年11月18日 星期一

.燕俠語錄 20241118: 「成功的人是跟別人學習經驗,失敗的人只跟自己學習經驗。」--- 墨者燕俠(劉建春)

2024年11月17日 星期日

[Python] 6/49 Big Lottery 大樂透 程式, 過了今晚!

. [Python] 6/49 大樂透 程式, 過了今晚!.
.
.
import random

lotterys = random.sample(range(1,50), 7)
specialNum = lotterys.pop()

print("大樂透 中獎號碼: ", end="")
for lottery in sorted(lotterys):
    print(lottery, end=" ")
print("\n特別號: ", specialNum)
print("過了今晚!")

執行結果範例:
PS D:\DevTool\ZCode> & C:/Python312/python.exe d:/DevTool/ZCode/_Code/_Python/BigLotterys.py
大樂透 中獎號碼: 13 19 22 34 40 43 
特別號:  32
過了今晚!



2024年10月27日 星期日

[Python] 字典 dict { } 的 key, value 鍵、值 互換

.[Python] 字典 dict { } 的 key, item 鍵、值 互換
 
--- --- --- --- --- --- --- --- ---
(1) 字典鍵值互換, 方法一 for 循環:
mydict = {'a': 1, 'b': 2, 'c': 3}
mydict_new = {}
for key, value in mydict.items():
    mydict_new[value] = key

print(mydict)
print(mydict_new)

---
>>> mydict = {'a': 1, 'b': 2, 'c': 3}
>>> mydict_new = {}
>>> for key, value in mydict.items():
...      mydict_new[value] = key
...
>>> print(mydict)
{'a': 1, 'b': 2, 'c': 3}
>>> print(mydict_new)
{1: 'a', 2: 'b', 3: 'c'}
>>>

--- --- --- --- --- --- --- --- ---
(2) 字典鍵值互換, 方法二 列表生成器 generator:
mydict = {'a': 1, 'b': 2, 'c': 3}
mydict_new = dict([value, key] for key, value in mydict.items())
print(mydict)
print(mydict_new)

---
>>> mydict = {'a': 1, 'b': 2, 'c': 3}
>>> mydict_new = dict([value, key] for key, value in mydict.items())
>>> print(mydict)
{'a': 1, 'b': 2, 'c': 3}
>>> print(mydict_new)
{1: 'a', 2: 'b', 3: 'c'}

--- --- --- --- --- --- --- --- ---
(3) 字典鍵值互換, 方法三 zip:
mydict = {'a': 1, 'b': 2, 'c': 3}
mydict_new = dict(zip(mydict.values(), mydict.keys()))
print(mydict)
print(mydict_new)

---
>>> mydict = {'a': 1, 'b': 2, 'c': 3}
>>> mydict_new = dict(zip(mydict.values(), mydict.keys()))
>>> print(mydict)
{'a': 1, 'b': 2, 'c': 3}
>>> print(mydict_new)
{1: 'a', 2: 'b', 3: 'c'}





[Python] 傳回 ASCII 的 chr() 函數 vs 傳回字元的 Unicode 碼值 ord() 函數

.[Python] 傳回 ASCII 的 chr() 函數 vs 傳回字元的 Unicode 碼值 ord() 函數

(1) 傳回 ASCII 的 chr() 函數:
>>> x1 = 65
>>> x2 = 66
>>> print(chr(x1))  // 或是 print(chr(65))
A
>>> print(chr(x2))  // 或是 print(chr(66))
B
>>>

---
>>> y1 = 97
>>> y2 = 98
>>> print(chr(y1))  // 或是 print(chr(97))
a
>>> print(chr(y2))  // 或是 print(chr(98))
b

.
(2) 傳回字元的 Unicode 碼值 ord() 函數:
>>> ch11 = 'A'
>>> ch12 = 'B'
>>> print(ord(ch11))  // 或是 print(ord( 'A'))
65
>>> print(ord(ch12))  // 或是 print(ord( 'B'))
66
>>>

---
>>> ch21 = 'a'
>>> ch22 = 'b'
>>> print(ord(ch21))  // 或是 print(ord( 'a'))
97
>>> print(ord(ch22))  // 或是 print(ord( 'b'))
98


2024年10月12日 星期六

[Python] name_list.reverse() and name_list[::-1]

(1) 方法1: name_list.reverse()
(2) 方法2: 使用 slice 切片 name_list[::-1]
.
# Example 1:
python3
>>>
>>> cars = ['Honda', 'BMW', 'Toyota', 'Ford']
>>> cars
['Honda', 'BMW', 'Toyota', 'Ford']
>>> cars[::-1]
['BMW', 'Ford', 'Toyota', 'BMW', 'Honda']
>>> cars.reverse()
>>> cars
['Ford', 'Toyota', 'BMW', 'Honda']
.
.
# Example 2:
>>> nums1 = [5, 3, 9, 2]
>>> nums1
[5, 3, 9, 2]
>>> nums2 = nums1[::-1]
>>> nums2
[2, 9, 3, 5]
>>> nums1.reverse()
>>> nums1
[2, 9, 3, 5]
.

2024年10月5日 星期六

Free ChatGP 3.5 for (TOEIC) English Speaking Practice / 免費 ChatGP 3.5 練習(多益)英語口說

.
Free ChatGP 3.5 for (TOEIC) English Speaking Practice / 免費 ChatGP 3.5 練習(多益)英語口說
.
// --- --- ---
. 簡單三步驟搞定: 
. (1) 將下列 0001、0002 指令貼到 ChatPGT 訊息視窗
. (2) 點選右下角 進階語音
.   
. (3) 開始練習
.   
.
// --- --- ---
Prompt 00001 (第0001指令)
Please remember: I may try to speak Chinese to you. But you can only answer me in English, no Chinese. That’s very important.
Purpose: I mainly use ChatGPT to learn TOEIC English.
Occupation: I am currently a Software Engineering.
English Proficiency: Basic level, so please use simple words when talking to me.
English Training Content: Mainly repetition and answering questions.
When I want to practice repetition: I will tell you, "I want to practice repetition." Please read the sentence for me to repeat after you.
When I want to practice answering questions: I will tell you, "I want to practice answering questions." Please ask me questions randomly from my specified sentences.
.
// --- --- ---
Prompt 00002 (第0002指令)
When I practice TOEIC English, I hope ChatGPT can follow these replies: You need to read the sentence one by one for me to repeat or answering questions. Response Language: Remember, please always reply in English. Even I speak in Chinese, you still need to response me in English. 
That’s very important.
.
Shadowing Practice Steps: 
First, I'll give you some sentences, and you'll read them to me in order. You need to read the following sentences one by one. 
Second, I'll shadow each sentence after you. 
Third, you'll tell me which word I pronounced unclearly, and ask me to repeat the word again until I say it right. If I keep saying the word wrong, please keep asking me to repeat until I say the word correctly. 
Fourth, read the next sentence for me so I can repeat after you. 
Fifth, after I finish all the sentences. Please show me a table of my score of my fluency and accuracy for each sentence. Remember, I need a table of my scores. 
.
Answering Questions Practice Steps: 
First, I'll give you three questions, and you'll ask me those questions randomly. You need to ask the questions I provided one by one. 
Second, I'll try to answer the question you ask me.  
Third, Very important step here. Do make sure you follow. you need to ask me one further question based on the answer I said. 
Fourth, ask me the next questions. 
Fifth, after I finish answering all three questions. Please show me a table of my score of my “Pronunciation” and “The content”
.
.
.
// --- --- ---
Prompt 00003 (第00003指令)
如果你想練習影子跟讀 [請自行輸入想練習問答的句子]

Here are the sentences I want to practice shadowing one by one.

I discovered BTW Radio over 20 years ago and have been a regular listener of your evening programming for at least a decade. I just want to say how much I enjoy your newest offering. I’ve been interested by many of the authors that have been featured on the show so far, but last evening’s guest was especially interesting. I remember James from when he was a little boy. I worked with his parents when they lived in New York, and I recall seeing James in his parents’ studio most days after he got out of school. I was surprised to learn that he has written about his childhood, and I look forward to reading his new book. 

Thank you for the excellent program. 
.
.
// --- --- ---
Prompt 00004 (第00004指令)
如果你想練習問答 [請自行輸入想練習問答的句子]
Here are the sentences I want to practice questions answering.

Bremen, Richard [9:34 A.M.]: 
I just got off the phone with them. It looks like everything will arrive on Monday afternoon, so we 
could actually begin the job on Tuesday. 
 
Vega, Camila [9:35 A.M.]: 
That’s good news. I’ll call the client this morning and let them know. 
 
Bremen, Richard [9:35 A.M.]: 
You should also remind them that we will begin working on the guestrooms first and work our way 
toward the lobby and first-floor public areas last. We’ll send a large crew so the work can be 
finished quickly. 
 
Kato, Yuri [9:36 A.M.]: 
How long do you think it will take to complete the job? 
 
Bremen, Richard [9:37 A.M.]: 
We can probably be finished by Friday, as we originally planned. 
 
Kato, Yuri [9:38 A.M.]: 
Excellent. They’re a new client with several locations and a high profile in the business community, 
so I want things to go smoothly. I’m sure there will be more work with the in the long run if all goes 
well. 
.

2024年3月8日 星期五

[Python] Remove elements from a list

.
[Python] Remove elements from a list
.

(1) Using the del keyword
(2) Using the list.remove(x) method
(3) Using the list.pop([x]) method

... ... ...
(1) Using the del keyword:
# Sample Code 1
list1 = [0, 1, 2, 3, 4, 5, 6]
del list1[0]
print(list1)
# [1, 2, 3, 4, 5, 6]

del list1[-1]
print(list1)
# [1, 2, 3, 4, 5]

del list1[:2]
print(list1)
# [3, 4, 5]


(2) Using the list.remove(x) method:
# Sample Code 2
list1 = [0, 1, 2, 3, 4, 5, 6]
list1.remove(2)
print(list1)
# [0, 1, 3, 4, 5, 6]


(3) Using the list.pop([x]) method:
# Sample Code 3
list1 = [0, 1, 2, 3, 4, 5, 6]
list1.pop()
print(list1)
# [0, 1, 2, 3, 4, 5]
list_removed = list1.pop(4)
print(list1)
# [0, 1, 2, 3, 5]


// End

[Python] Concatenate Lists / Merge Lists in Python

.
[Python] Concatenate Lists / Merge Lists in Python
.

(1) Concatenating Lists with "+" Operator
(2) Utilizing the Extend() Method
(3) Applying the Itertools.chain() Function
(4) Native Method for List Concatenation (list.append())
(5) List Comprehension to concatenate lists

... ... ...

2024年1月1日 星期一

[Python] Python String format 字串格式化 : (1) 舊式字串格式化 %-formatting (2) 新式字串格式化 str.format() (3) 字串插值 f-string (Formatted String Literal) (4) Template Strings

.


Python 在處理字串時, 由於版本的演變, 有太多種方法, 所以很容易搞混. 筆記整理一下.
.


(1) 舊式字串格式化 %-formatting:

string interpolation

初代 format string, 這是類似 C語言 printf 語法, 使用 % 格式, 
例如: %s (字串), %d (十進位整數), %f (浮點數), 將 tuple 中的一組變量依照指定字串格式輸出.

# Example 1.1:
text = 'World'
print('Hello %s' % text)
# Hello world


# Example 1.2:
name = "John"
age = 23
print('%s is %d years old.' % (name, age))
# John is 23 years old.


# Example 1.3:
print('%x' % 11)  # 轉成十六進位
# b

(2) 新式字串格式化 str.format()

Python 2.6 (發布於 2008 年), 開始有新式字串格式化 str.format(), 透過{} 和 format 來代替 % 運算符號.

# Example 2.1:
text = 'World'
print('Hello {0}'.format(text))
# Hello world
print('Hello {}'.format(text))
# Hello world


# Example 2.2:
name = "John"
age = 23
print('{0} is {1} years old.'.format(name, age))
# John is 23 years old.
print('{} is {} years old.'.format(name, age))
# John is 23 years old.


# Example 2.3:
print('{:x}'.format(11))  # 轉成十六進位
# b


# Example 2.4:
print('{:.2f}'.format(3.1416))  # 保留小數點後兩位
# 3.14


# Example 2.5:
print('{:+.2f}'.format(3.1416))  # 帶符號保留小數點後兩位
# +3.14


細節可以參考 Ref3: Python format 格式化函数


(3) 字串插值 f-string (Formatted String Literal)

Python 3.6 (發布於 2016 年) 新增 f-string, 解決變量不易閱讀以及變量超長的問題.

# Example 3.1:
text = 'World'
print(f'Hello {text}')
# Hello world



# Example 3.2:
name = "John"
age = 23
print(f'{name} is {age} years old.')
# John is 23 years old.


# Example 3.3:
print(f'{11:x}')  # 轉成十六進位
# b


# Example 3.4:
print(f'{3.1416:.2f}')  # 保留小數點後兩位
# 3.14
a = 3.1416
print(f'{a:.2f}')  # 保留小數點後兩位
# 3.14


# Example 3.5:
print(f'{3.1416:+.2f}')  # 帶符號保留小數點後兩位
# +3.14


細節可以參考 Ref4: 制霸 Python f-string 各種格式使用方法


(4) Template Strings:

# Example 4.1:
from string import Template
name = 'Bob'
t = Template('Hey, $name!')
t.substitute(name=name)
# 'Hey, Bob!'


--- --- ---

同場加映 : Python String 字串 join() 語法


# Example 5.1:
chars = ['P', 'y', 't', 'h', 'o', 'n']
text = "".join(chars)
print(text)  # 顯示:Python


# Example 5.2:
chars = ['P', 'y', 't', 'h', 'o', 'n']
text = "##".join(chars)
print(text)  # 顯示:P##y##t##h##o##n


# Example 5.3:
words = ["Python", "is", "awesome"]
text = " ".join(words)
print(text)  # 顯示:Python is awesome

Ref2: 如何使用 Python 進行字串格式化

Ref3: Python format 格式化函数

Ref4: 制霸 Python f-string 各種格式使用方法

Ref5: Python String Formatting Best Practices

// End.