Monday, September 22, 2008

range vs xrange

In Python, you can create a list of numbers (arithmetic progression) using range( )

>>> range(10)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> range(5, 10)
[5, 6, 7, 8, 9]
>>> range( 2, 10, 2)
[2, 4, 6, 8]

>>> type(range(10))

range() returns a list of numbers - We may not need an explicit list for most of our purposes - We may require only one item of the list at any point of time for typical applications -

for i in range(10):
print i

While executing the above code, the call to range(10) creates a list with elements [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]. Then, i iterates over this list. However, creating the list this takes up memory, which is not actually required.

We can use a generator based method xrange() - xrange can be used instead of range in most applications where you do not require all the elements to be in memory.

for i in xrange(10):
print i

This code will behave identical to the previous version of the code that uses range(10) - However, memory is saved since it uses a generator based approach than creating the whole list in memory.

You can check that it does not produce the entire list:
>>> type(xrange(10))


xrange is an iterable container, that returns only the next element in the list. So, whenever you don't need the entire list in memory, go ahead use xrange() and save some memory :-)


Monday, September 08, 2008

A joke called Project6xn - Nokia N96


When Apple was launching its iPhone, Nokia decided to steal its thunder - They prelaunched Nokia N96! Wow! What a great strategy! 

The only problem is that I dont understand what a pre-launch means - Does it mean you release photos / specs of a product? Or show a dummy of the product? 

I think what it all meant was to tell people not to burn their hard earned money over iPhone (which I think is right way of thinking considering it has a 2 MP camera, and you cannot take videos, and cannot forward a picture over Bluetooth to your friend) - And no.. you cannot send MMS to your friend too - Please send your photo as an email - Thank you!

Coming back to Nokia N96, they decided to launch a webpage that would grab the attention of high end mobile users! Enter - www.project6xn.com. You have to register as a new detective, and after verifying your email, you can do something. (Btw, I never got through email verification - And yes, I checked my bulk mail folder!)

Then there was a couple of days for launch.. (By Aug mid) - I was pretty excited! And, on the D day, the website showed 7 more days (unless the website went through a worm hole and time warped, it couldn't gain time!) - A few more days later, believe me it showed 10 days more to launch!

I couldnt contain my excitement! Time was flowing in the opposite direction! (I now know that the total entropy of the Universe was decreasing, since the time is supposed to flow from a low entropy to high entropy state. I am surprised major cosmologists have not noticed it)

And then, when the project slipped further, the time became negative. Please look at the screenshot above.

The first stanza of Mandukya Upanishad says - 'Om is everything. Om is Past, Present and Future. It is also beyond all these three'. (How can something not be in one of Past / Present / Future? The Upanishad hints that for the Almighty, time is nothing a but one of multitude of dimensions, and hence time does not define 'Om' completely)

I am severely moved by this Nokia website competing with Om for it truly transcends time (I am getting emotional here)

Nokia! For HEAVEN'S SAKE stop this joke. And remove the website. It is all but an eye sore. (I am sure I shouldn't be doing this.. but let me quickly check the website if the phone has launched... 

Holy Crap! @#@$#$$#%$%^$ )




Tuesday, September 02, 2008

Google Chrome!

I just happened to stumble across the Google Chrome comics
http://www.google.com/googlebooks/chrome/#

And also the official Google blog entry:
http://googleblog.blogspot.com/2008/09/fresh-take-on-browser.html

Boy, am I excited!!! Based on the comic, I can see that Google is taking the browser in the right direction. It may stand to benefit from the whole stuff, but still!

I think google's idea of using popular ideas of computer operating systems in a browser is pretty cool. What we get is time tested techniques in a new platform (browser). None of the ideas are like earth-shatteringly new, but it makes a real innovative mind (or lots of them) to come up with a new browser grounds up like this! Javascript VM implementation that compiles to native in the browser, is quite radical though.

It takes great guts and spirit to open source the entire browser and the entirely new V8 Javascript .

Google Chrome is not available for download (yet), but going by what is there in the comic, I think this a great step forward for the entire web programming domain as a whole! I'll sure check it out tomorrow, when it launches!

Hats off, Google!