Search one element of a list in another list recursively

Posted by androidnoob on Stack Overflow See other posts from Stack Overflow or by androidnoob
Published on 2012-06-12T04:28:25Z Indexed on 2012/06/12 4:40 UTC
Read the original article Hit count: 160

Filed under:
|

I have 2 lists

old_name_list = [a-1234, a-1235, a-1236]
new_name_list = [(a-1235, a-5321), (a-1236, a-6321), (a-1234, a-4321), ... ]

I want to search recursively if the elements in old_name_list exist in new_name_list and returns the associated value with it, for eg. the first element in old_name_list returns a-4321, second element returns a-5321, and so on until old_name_list finishes.

I have tried the following and it doesn't work

for old_name, new_name in zip(old_name_list, new_name_list):
    if old_name in new_name[0]:
        print new_name[1]

Is the method I am doing wrong or I have to make some minor changes to it? Thank you in advance.

© Stack Overflow or respective owner

Related posts about python

Related posts about list