看板 [ Python ]
討論串[問題] Python新手 for迴圈問題
共 5 篇文章
首頁
上一頁
1
下一頁
尾頁

推噓5(5推 0噓 3→)留言8則,0人參與, 5年前最新作者a172545056 (Leon)時間5年前 (2019/06/12 09:48), 編輯資訊
4
0
0
內容預覽:
各位前輩大家好,我是剛接觸python不久的新人,目前練習到for迴圈時有點卡關,想請教一下各位前輩. 我有三個List. ListA=[“Apple”,“food”,“Iron”]. ListB=[“x”,“z”,“on”]. ListC=[]. 今天我想知道ListA中的字串是否有包含ListB
(還有275個字)

推噓1(1推 0噓 5→)留言6則,0人參與, 5年前最新作者TuCH (謬客)時間5年前 (2019/06/12 10:08), 5年前編輯資訊
0
0
0
內容預覽:
稍微修改一下. if len(ListA) != len(ListB):. assert 'ListA 長度跟 ListB 長度不一致'. for a_index, a_str in enumerate(ListA):. b_str = ListB[a_index]. if b_str in a_s
(還有350個字)

推噓4(4推 0噓 7→)留言11則,0人參與, 5年前最新作者jordan0740 (鋒仔)時間5年前 (2019/06/12 16:29), 編輯資訊
0
0
0
內容預覽:
目前想到最有效率的寫法. ListA=["Apple","food","Iron"]. ListB=["x","z","on"]. ListC=["No","No","No"]. for i in range(len(ListA)):. if ListB[i] in ListA[i]:. ListC

推噓1(1推 0噓 0→)留言1則,0人參與, 5年前最新作者safyrose (三十飛)時間5年前 (2019/06/13 00:04), 編輯資訊
0
0
0
內容預覽:
幫你做個小修改就搞定了. for a_str in ListA:. xxx = 'No'. for b_str in ListB:. if b_str in a_str:. xxx = 'yes'. continue. ListC.append(xxx). --. 發信站: 批踢踢實業坊(ptt

推噓0(0推 0噓 0→)留言0則,0人參與, 最新作者alvinlin (艾爾文)時間5年前 (2019/06/13 00:16), 編輯資訊
0
0
0
內容預覽:
只需要一個for即可.. listA = ['Apple', 'food', 'Iron']. listB = ['x','z','on']. listC = []. for x,y in enumerate(listA):. if listB[x] in listA[x]:. listC.appe
(還有17個字)
首頁
上一頁
1
下一頁
尾頁