http://ideone.com/QaVoJ this was one of my solutions to the hw1 in udacity robotics class. Why is it giving a veeeery slightly different answer to the question, compared to the standard solution?
i can't understand anything in ur code where you use bazillion commands in one square brackets lol and why you use xrange?
that's mine code http://ideone.com/SoZU3 but it's probably written in not pythonic way :D
xrange is better than range if I'm just going to use the numbers; xrange is a generator that just yields numbers if you call it (requires less memory than an entire list), whereas range returns a list (requiring memory to store a whole list)
what happens if i type a=xrange(5)?
then a will be equal to a generator object 'xrange(5)'
so better always use xrange in for loop and use range only if you want to create list and assign it to some variable?
right
almost 2 times faster with 100millions >>> timeit.Timer('for i in xrange(100000000):pass').timeit(1) 2.7219030857086182 >>> timeit.Timer('for i in range(100000000):pass').timeit(1) 5.6206169128417969 but when i try to do with 1 billion >>> timeit.Timer('for i in xrange(1000000000):pass').timeit(1) 27.099134922027588 >>> timeit.Timer('for i in range(1000000000):pass').timeit(1) MemoryError
lol... did the python list of 1 billion integers kill your system?
not kill just memory error :D does it allow you to create such list?
My system only has 1GB of memory :(
why this doesn't work? a=[] timeit.Timer("for i in xrange(1000000000):a.append('')").timeit(1) gives NameError: global name 'a' is not defined timeit.Timer("a=[];for i in xrange(1000000000):a.append('')").timeit(1) gives SyntaxError: invalid syntax
in a.append its double single '
try defining a function, and then timing that. will it still give errors? never used timeit myself :(
can you make void function? what my function should return? or just anything
If you don't have a `return' keyword anywhere in the function, or if you use `return' alone (without an expression), then the function returns `None'
NameError: global name 'testbillion' is not defined
after 5minutes and 12 second got memory error, but my RAM usage didn't increase at all looking at system monitor
however it created list of this length >>> len(a) 496880822
Join our real-time social learning platform and learn together with your friends!