Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Your condition can be terser : ...if max(flatten(j))<=12 should do the job.

But your main problem is that you have to read the whole b2 in memory before even starting to process it. Can you somehow (sed comes in mind...) restructure your input file in order to have exactly one element of b2 on each line ? If so, your program could simply do something along the lines of :

fp=open('Your/file/name.txt')
L=[]
l=fp.readline()
while l :
    j=eval(l)
    if max(flatten(j))<=12: L.append(j)
    l=fp.readline()
fp.close()

HTH,