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.

2023年12月13日 星期三

Angular 超級入門教學 000

...
Angular 超級入門教學 000
...

1. https://angular.io/   or   https://angular.tw/ 

2. Install Node.js JavaScript runtime:
from https://nodejs.org/en
to D:\DevTool\nodejs\

3. Install Visual Studio Code:
from https://code.visualstudio.com/

4. Install the Angular CLI:
from https://angular.io/guide/setup-local
CMD> npm install -g @angular/cli

5. Create a workspace and initial application:
CMD> cd D:\DevTool\Angular
CMD> ng new HelloWorld
CMD> cd D:\DevTool\Angular\HelloWorld
CMD> npm start
> hello-world@0.0.0 start
> ng serve
Local:   http://localhost:4200/

後記1:
CMD> npm start
對應到 package.json




// End

2023年12月12日 星期二

.燕俠語錄 20231212: 吾日三省吾身: 我是誰? 我在哪? 我在這邊做什麼? --- 墨者燕俠(劉建春)

曾子曰:「吾日三省吾身,為人謀而不忠乎?與朋友交而不信乎?傳不習乎?」