windows - Python behavior -


i did simple test, tried take square of numbers till 50.000.using python 3.4.

first tried;

num=range(1,50000) sq=lambda x:x**2 print (list(map(sq,num))) 

i got error python stop working.

then tried;

sqlist=[] x in range(1,50000):     sq=x**2     sqlist.append(sq) print (sqlist) 

i got same error again,stop working.

then tried while loop;

sqlist=[] t=1 while t<50001:     t+=1     sq=t**2     sqlist.append(sq) print (sqlist) 

again same error, while loop survived more for loop.

last test is;

sqlist=[] sqlist1=[] sqlist2=[] sqlist3=[] sqlist4=[] t=1 while t<50001:     t+=1     sq=t**2     if t<10000:         sqlist.append(sq)     elif t<20000:         sqlist1.append(sq)     elif t<30000:         sqlist2.append(sq)     elif t<40000:         sqlist3.append(sq)     elif t<50000:         sqlist4.append(sq)  print (sqlist,sqlist1,sqlist2,sqlist3,sqlist4) 

and got want, no error,shows me squares of numbers till 50,000. did for loop too, , while loop faster for loop again.

so why while loop faster for loop , why need bunch of lists? why single list throwing error?also last way has more process others, more codes more things check etc.

i think using idle. idle doesn't work large amounts of text (afaik problem tk). don't print list.

to view list, instead write list file.

with open("squareslist.txt") f:     f.write(str(sqlist)) 

and view squareslist.txt file in text editor such notepad.

or view individual elements of list, e.g.

print(sqlist[13]) 

Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -