作者: bongbong3481 時間: 2023-9-8 16:52 標題: 發覺人工智能真系西厲
自己有2段python for in range code(下面), 因為速度問題, 研究python list comprehension, 搵左好耐資料同埋諗左耐都寫唔出, 醒起可以問BING CHAT, BING CHAT幾秒就寫左句野出黎 list4 = [list3[list2.index(txt)] if txt in list2 else None for txt in list1] , 我測過結果, 同下面一樣。
===============
for i in range(10000):
txt=list1[i]
for c in range(150000):
if txt==list2[c]:
list4[i]=list3[c]
break
===============
作者: s20012797 時間: 2023-9-10 16:12
自己有2段python for in range code(下面), 因為速度問題, 研究python list comprehension, 搵左好耐資 ...
bongbong3481 發表於 2023/9/8 16:52
This list comprehension can be improved by using the in operator to check if txt is in list2 before indexing list3. This will avoid the need to iterate over the entire list list2 for each txt in list1.
The improved list comprehension would be:
list4 = [list3[list2.index(txt)] if txt in list2 else None for txt in list1]
The original list comprehension iterates over the entire list list2 for each txt in list1, even if txt is not in list2. This can be inefficient if list2 is large.
The improved list comprehension uses the in operator to check if txt is in list2 before indexing list3. This avoids the need to iterate over the entire list list2 for each txt in list1.
The improved list comprehension is therefore more efficient than the original list comprehension.
革命尚未成功、BING CHAT同志仍須努力。--孫文
作者: bongbong3481 時間: 2023-9-11 20:15
回覆 2# s20012797
我暫時都吾明點解,比普通for loop 快咁多,照計大家都放系ram 運算,速度應該吾差太遠,真是吾明。
作者: llucas 時間: 2023-9-11 20:46
提示: 作者被禁止或刪除 內容自動屏蔽
作者: s20012797 時間: 2023-9-11 21:01
本帖最後由 s20012797 於 2023-9-11 21:06 編輯
Python's list comprehensions are often faster than for loops because they're optimized for the Python interpreter. Python's list comprehension is more efficient both computationally and in terms of coding time and space than a for loop.
作者: s20012797 時間: 2023-9-11 21:17
回復 bongbong3481
chatgpt plus + code interpretor 你聽過未?
via HKEPC Reader for Android
llucas 發表於 2023/9/11 20:46
你確定本身對code 0理解,光靠plus + code interpretor 就有用???


作者: llucas 時間: 2023-9-12 00:04
提示: 作者被禁止或刪除 內容自動屏蔽
作者: gronasu 時間: 2023-10-15 16:43
回覆 1# bongbong3481
Yes, Ai is more mature than before.

