Lists of list

M

Mohammed Altaj

Hi All

I am having problem with delete line if its belong to another one , example

['0132442\n', '13\n', '24\n']

the 2nd and 3rd are already in the first line , how can do this !!!

Thanks
 
B

BranoZ

Mohammed said:
Hi All

I am having problem with delete line if its belong to another one , example

I think, you mean to remove all lines that are substrings of another
line.

l = ['0132442\n', '13\n', '24\n']
l = [e.strip() for e in l]

i = 0
while True:
try:
for j in range(len(l)):
if i == j:
continue
if l[j].find(l) >= 0:
# line 'j' is superstring of line 'i'
del l
break
else: # doesn't have superstring
i += 1
except IndexError:
break

Basically, I try all n*n combinations, and remove substring lines
"in-place".

BranoZ
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top