Iterating over a list of lists and ignoring strings if they appear inside a larger string - Python -


i want iterate on list of lists, , check if of strings in second position in of other strings in second position. if are, skipped over. want return strings first position larger string. needs work strings in list.

this description horrific, here example.

record = [['436', 'university'], ['123', 'university hospital'], ['956', 'school']] 

the output want here is:

'123 956' 

this because "university" in "university hospital", not need number associated it.

i have had no luck coming solution, , best do:

final_string = '' inst in record:     if inst[1] not in record:          final_string = final_string + inst[0] + ' ' 

this returns strings in first position, i.e.

'436 123 956 ' 

this work.

for i, inst in enumerate(record):     append = true     rec in (x[1] x in record[i + 1:]):         if inst[1] in rec:             append = false             break     if append:         final_string = final_string + inst[0] + ' ' 

to make performance improvements can cache searched words, that's topic!

hope helps!


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

[C++][SFML 2.2] Strange Performance Issues - Moving Mouse Lowers CPU Usage -

gradle error "Cannot convert the provided notation to a File or URI" -