how can two arrays be compared to return a match with python? -


i have dataset1 in format

 ['tyuri:12345', 'hsksfd:58380', 'shskfks:49539'] 

and dataset2 in format

 ['12345', '442342', '8053308'] 

i want compare dataset1 dataset2 , have return

 tyuri:12345 

i know using set().intersection() compare 2 arrays , return exact match. how implement comparing these 2 arrays produce desired output?

you can try this:

a = ['tyuri:12345', 'hsksfd:58380', 'shskfks:49539'] b = ['12345', '442342', '8053308'] new_a = [i in if any(i.endswith(c) c in b)] 

output:

['tyuri:12345'] 

in new_a, list comprehension used find elements have trailing digit exists in b. find values, any() function used determine if 1 or more trailing values, found endswith() method, contained in b.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -