我有包含多個值中的每個陣列的字典。Python字典陣列 - 一線每值
upcthreadsmall.txt
包含一系列的UPC號碼 「000381001184」, 「000381102935」, 「000381003263」 等
隨着下面的代碼作爲顯示:
000381002365 : ['$265.29', '$299.00', '$270.70', '$299.00']
我想它,以顯示如:
000381002365 : $265.29
000381002365 : $299.00
000381002365 : $270.70
000381002365 : $299.00
代碼:
def th(ur):
base = "https://www.slickguns.com/search/apachesolr_search/"+ur
regex = '<td class="price-column">(.+?)</td>'
pattern = re.compile(regex)
htmltext = urllib.urlopen(base).read()
results = re.findall(pattern, htmltext)
try:
gmap[ur] = results
except:"got an error"
upclist = open("upcthreadsmall.txt").read()
upclist = upclist.replace(" ","").split(",")
threadlist = []
for u in upclist:
t = Thread(target=th,args=(u,))
t.start()
threadlist.append(t)
for b in threadlist:
b.join()
for key, upc in gmap.items():
print(key)
for attribute, value in gmap.items():
print('{} : {}'.format(attribute, value)
看起來像你只需要以另一個'for'循環'的屬性,價值gmap.items( ):'? '在價值項目:打印(「{} {}」。格式(屬性,項目)'但你似乎已經明白嵌套循環所以覺得我失去了一些東西 – roganjosh
@roganjosh謝謝你的提示我。相信我已經到位 – hinteractive02
在這種情況下,它應該在你貼的代碼,因爲如果'000381002365:[「$ 265.29」,「$ 299.00」,「$ 270.70」,「$ 299.00」]'是'打印的實際輸出(「{} {}」。格式(屬性值)'然後你錯過了另一個循環 – roganjosh