First of all, you should create meaningful variable names. For instance, what are lst1 and lst2? Wouldn't it make more sense to call them primes and compounds?
Your test for primes is logically incorrect. What you do is this:
- Test if a number can be divided without any remainder by a
- If there is a remainder, you put it into list1 (primes?, compound numbers?) and stop the loop
- If there is no reminder, you put it into list2, but you keep doing your innermost loop so potentially you would put the same number in the other list as well or even the same list again.
A correct (but not the most efficient) way to test for prime would be like this (your loop conditions are correct: for a in range(2, mat[i][j]))
- If the number in test can be divided by any of the values of a, then it is a compound number. Put it in the compounds list and terminate the innermost loop.
- If you finish the innermost loop without putting your a into the compounds list, then it had no whole dividers, hence it is a prime and should go into the primes list.
I hope this helps.
Good luck with the implementation!