2014-10-10 217 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 

但你必须要更具体,如果你想更具体的答案。