Looking for matches within different lists of different formats using for loops

Viewed 23

In Python I am trying to search lists of numbers for a single number contained in these strings. If the first number (46424409) is contained within any of the total rows, the row containing that particular number should be added to a separate group. After performing this search on the first number, it will do the same for the second number etc.. until there is no match to be found: Example data:

[46424409,51337324248,5173349797,5179273316,5331867664,5183367665]
[46800409,5113033868,5122425797,51325252716,513333664,51867633365]
[44440409,51730868,5242449797,513533716,51867664,51867665]
[4683300409,5173330868,5173349797,51792716,5111664,51844565]


found3 = []
for num in total_list:
    print(num)
    for j in row_list:
        print(j)
        print('row list element')
        if num in j:
            found3.append(j)
        else:
            if num not in j:
                break

(row_list is a row, total_list is all rows combined) this works but only if I omit not use the first for loop over the total list, now it goes wrong and I get a repetition of the first row list.

Does anybody know how to integrate the second for loop?

0 Answers
Related