Filtering by postion : first one (第一個), 第x個 (某一個), last one (最後一個), 單數/雙數
May 21, 2022
在開始之前,先學會COUNT 一個字串的長度
function: len()
s="1234567" len(s)
expected result: 7
接下來,要著意python 第一個值是 0 ; 最後一個值是 -1
s=”1234567″ # Python initial position is 0 s[0]
所以first one : s[0]
# Python last position is -1 s[-1]
所以last one : s[-1]
再來就是抽某一個範圍的數值
s=”1234567″
s[x:n] —– 其中x, n為數字; 代表第x個位置開始抽,抽到第 N-1 個位置 ; 例子:
# 由第x個位置開始抽,抽到第 N-1 個位置 # 由第0個位置抽,抽到第 2-1 個位置 # 即抽 0 TO 1的數值 s[0:2] #由第0個位置抽,抽到第 1-1 個位置 #即抽0的數值ONLY~ s[0:1] #由第1個位置抽,抽到1-1個位置 #即抽 1 TO 0 的數值 - 明顯LOGIC 有問題~ s[1:1] #由第1個位置, 抽到2-1個位置 #即抽1 TO 1的數值 s[1:2] #由第1個位置, 抽到 3-1個位置 #即抽1 TO 2 的數值 s[1:3]
現在,再來一些深入點的例子:
s[:] 代表全部都抽 ;
s[0:-1] 代表 由第0 TO (最尾-1) 個
所以如果想要埋第後一個就應該用 s[0:]
Filtering position 亦可以用來抽單數/雙數的值 – 但要用到stepping
抽單數
s = "1234567"
#先抽s 全部,再每 N + 2的抽
s [::2]
即抽第0,2,4,6,8 – 對應的值 s[0], s[2], s[4], s[6], s[8] ….
所以1,3,5,7……..
抽雙數
先IGNORE 1,由2開始,再每N+2的抽
s[1::2]
即會先抽了 234567 ,每對應抽s[0], s[2], s[4], s[6], s[8] ….
所以2,4,6,8……..
Calendar
S | M | T | W | T | F | S |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Archives
- January 2025
- December 2024
- November 2024
- October 2024
- September 2024
- August 2024
- July 2024
- June 2024
- May 2024
- April 2024
- March 2024
- February 2024
- January 2024
- December 2023
- November 2023
- October 2023
- September 2023
- June 2023
- May 2023
- April 2023
- March 2023
- July 2022
- May 2022
- April 2022
- August 2021
- April 2021
- March 2021
- February 2021
- December 2020
- November 2020
- October 2020
- September 2020
- August 2020
- July 2020
- June 2020
- May 2020
- April 2020
- March 2020
- February 2020
- January 2020
- December 2019
- September 2019
- June 2019
- May 2019
- April 2019
- March 2019
- February 2019
- January 2019
- December 2018
- November 2018
- October 2018
- July 2018
- June 2018
- May 2018
- April 2018
- March 2018
- February 2018
- January 2018
- December 2017
- November 2017
- October 2017
- September 2017
- June 2017
- March 2017
- January 2017
- December 2016
- August 2016
- July 2016
- June 2016
- May 2016
- April 2016
- March 2016
- January 2016
- December 2015
- November 2015
- October 2015
- September 2015
- March 2014
- September 2013
- August 2013
- March 2013
- September 2012
- August 2012
Categories
- AFTC training
- AGK – Airframe, Engine, System
- AGK – Instruments
- ATPL Knowledge
- Aviation
- Aviation English
- BAK
- BC Life in CTB
- Book Sharing
- Books of OSH
- Cathay Pacific
- CNY Trip 2019
- CNY trip 2020 (Malaysia)
- Coffee
- Communication
- Corporate Governance
- English Learning
- Environmental Management
- ERM (enterprise risk management)
- Excel
- First Step Summit
- Flight International (Magazine)
- Flight planning and Monitoring
- HKMA ADMS
- Human Performance and Limitations
- Introduction to OHS
- IT
- Korea Trip 2019
- Learn from aviation accident
- Legislative Context in OHS
- London + Paris 2013
- Macau @ Trip 2017
- Meteorology
- Microsoft Windows
- MOLDOVA CHALLENGE
- My Diaries
- My Travels
- Navigation
- Occupational Health and Safety (OSH)
- Operational Procedures
- Operations Management
- Organizational Behavior
- OSH English
- Power BI
- Preparation
- Principal of Flying
- Python
- Quality Management System (QMS)
- Radio Navigation
- Regulations, Rules and Practices
- Risk Assessment
- Road to be an airline cockpit crew
- Route Training
- Summer Trip 2018
- Taiwan trip 2016
- The life in VHHH
- The road to be a pilot
- The road to be a RSO
- Uncategorized
- Weight & Balance
- 學車 in CTB
- 私牌系列
- 馬來西亞 (怡保+檳城) 2024