2014-10-10 209 views
-1

搜索一個字,我想寫的是專門在列表中搜索一些功能:嵌套列表

def search(inlist, matches): 
    for li in inlist: 
     for m in matches: 
      if m in li: 
       return li 
    return none 

l = [("daniel", "20th november", "tenochtitlan"), ("Arturo", 17, "17th october")] 

這裏,例如,尋找丹尼爾的生日。

我有這個來定義搜索,但我不知道如何從這裏走。

+1

你的問題的標題,代碼和你想要的是不同的。更清楚地解釋你想要什麼。 – 2014-10-10 19:44:48

+0

當我拿這段代碼(刪除了'return none'或用正確但不必要的'return None'替換它),它似乎完全按照你的意思去做。特別是,'search(l,['daniel'])''return'('daniel','11月20日','tenochtitlan')''。如果這是錯誤的,那麼你想要什麼_do_?編輯你的問題給我們輸入,所需的輸出和實際輸出。 – abarnert 2014-10-10 19:47:55

回答

-1

從寫有代碼我得到這個:

l = [("daniel", "20th november", "tenochtitlan"), ("Arturo", 17, "17th october")] 
data = search(l, ['daniel']) 
#data will be ("daniel", "20th november", "tenochtitlan") 
for d in data: 
    #regexp to find something specific, return that value 
    if SomeRegexp.match(d): 
     return d 

但你必須要更具體,如果你想更具體的答案。