我有乙個主列表,它基於2個子列表。我想用「search_value」引數建立乙個函式,並列印「search_value」項的索引位置,包括子列表的列表索引。在
示例:grocery = ["juice", "tomato", "potato", "banana", "milk", "bread"]
clothes = ["shirt", "pant", "jacket", "sweater", "hat", "pajama", "t-shiraz", "polo"]
master_list = [grocery, clothes]
預期結果:
^$我不熟悉python&已經編寫了工作**。只想知道如何用更少的努力去做def function(in_coming_string_to_search):
grocery = ["juice", "tomato", "potato", "banana", "milk", "bread"]
clothes = ["shirt", "pant", "jacket", "sweater", "hat", "pajama", "t-shiraz", "polo"]
master_list = [grocery, clothes]
length = int(len(master_list))
print master_list, "list has:", length, "list items", '\n'
to_do_list_first_array_index = 0
counter = 0
list_one_length = int(len(master_list[0]))
while counter < list_one_length:
for a in master_list[to_do_list_first_array_index]:
# print a
if a == in_coming_string_to_search:
print "the item you searched for is", in_coming_string_to_search, ". it is in the first list with index position of:", counter
counter = counter + 1
to_do_list_second_array_index = 1
counter2 = 0
list_two_length = int(len(master_list[1]))
while counter2 < list_two_length:
for b in master_list[to_do_list_second_array_index]:
if b == in_coming_string_to_search:
print "the item you searched for is", in_coming_string_to_search, ". it is in the second list with index position of:", counter2
counter2 = counter2 + 1
if __name__ == '__main__':
string_to_search = "tomato"
function(string_to_search)
P2P打洞中遇到的問題
裝置a通過一台聯通的路由器上網,裝置a通過有線連線路由器 裝置b是一台手機是移動2g 協助伺服器是電信網路 附 裝置a和裝置b經過ip.cn 測試發現各自的外網位址是 裝置a 221.4.212.2,聯通ip,相對固定 裝置b 117.136.33.128,移動ip,手機網路經常變動 但是通過伺服器...
CAP理論中的P含義
乙個分布式系統裡面,節點組成的網路本來應該是連通的。然而可能因為一些故障,使得有些節點之間不連通了,整個網路就分成了幾塊區域。資料就散布在了這些不連通的區域中。這就叫分割槽。當你乙個資料項只在乙個節點中儲存,那麼分割槽出現後,和這個節點不連通的部分就訪問不到這個資料了。這時分割槽就是無法容忍的。提高...
P2P網路中的節點發現
在p2p網路中,要發現並連線其他節點,常見的是通過種子節點連線到網路,然後通過種子節點獲取其他節點的位址。以太坊的種子節點在cmd swarm bootnodes.go中定義,hpb的種子節點在config networkconfig.go中定義 以hpb節點為例說明 以太坊基本是一樣的。1 節點啟...