第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在Python中循環(huán)遍歷數(shù)組并并排打印每個索引?

如何在Python中循環(huán)遍歷數(shù)組并并排打印每個索引?

森林海 2024-01-16 15:49:29
簡而言之,我想打印三個數(shù)組,每個數(shù)組之間都有字符串。例如,print(item + string + description + string + price). 我有 3 個數(shù)組,但此代碼僅打印前六行。res = "\n".join("{} {} {} {} {} {} {}".format(html, x, html, z, html, w, html) for x, y, z, v, w in zip(itemList, html, priceList, html, descripList)) print(res)我很驚訝像這樣簡單的事情在 Stack Overflow 上還沒有得到解答,我發(fā)現(xiàn)的一切都不是實用的而是理論的。這是我的完整代碼:itemList=[]for tag in soup.find_all('a', class_=['menuItem-name']):    if tag not in itemList:        itemList.append(tag.text)descripList=[]for t in soup.find_all('span', class_=['u-text-secondary']):    if t not in descripList:        descripList.append(t.text)priceList=[]for g in soup.find_all('p', class_=['menuItem-displayPrice']):    if g not in priceList:        priceList.append(g.text)html="<html>"res = "\n".join("{} {} {} {} {} {} {}".format(html, x, html, z, html, w, html) for x, y, z, v, w in zip(itemList, html, priceList, html, descripList))print(res) 
查看完整描述

2 回答

?
守著一只汪

TA貢獻(xiàn)1872條經(jīng)驗 獲得超4個贊

將“<html>”放入 zip 將迭代該字符串中的所有 6 個字符,然后完成。嘗試:

res = "\n".join("{} {} {} {} {} {} {}".format(html, x, html, z, html, w, html) for x, z, w in zip(itemList, priceList, descripList))



查看完整回答
反對 回復(fù) 2024-01-16
?
隔江千里

TA貢獻(xiàn)1906條經(jīng)驗 獲得超10個贊

zip正在將其工作截斷為傳遞給它的最短迭代;它的參數(shù)之一的長度僅為 6


>> [x for x in zip(range(3), range(4), range(5))]

[(0, 0, 0), (1, 1, 1), (2, 2, 2)]


查看完整回答
反對 回復(fù) 2024-01-16
  • 2 回答
  • 0 關(guān)注
  • 156 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號