I am Hack Sparrow
Captain of the Internets.

Archive for Python

Ubuntu: how to install easy_install

So you need easy_install for something on Ubuntu? Installing it is very easy, just follow the instructions below. [code] $ sudo apt-get install python-setuptools [/code] And that's it! Yes, that's all you need to do and you will have easy_install available at the command prompt. In case you are wondering, easy_install is a Python module which comes as a part of the Python se ...

Python: length or size of list, tuple, array

Let me clarify something at the beginning, by array, you probably mean list in Python. list is the equivalent of arrays in JavaScript or PHP. Arrays in Python is an altogether different thing. Ok, having cleared that, getting the the size of a list or tuple (or array, if you will), is pretty straighforward. You just call the l ...

Python: difference between list and tuple

To put it lightly, tuples are lists which can't be edited. Once you create a tuple, you cannot edit it, it is immutable. Lists on the other hand are mutable, you can edit them, they work like the array object in JavaScript or PHP. You can add items, delete items from a list; but you can't do that to a tuple, tuples have a fixed size. Here is an example demonstrating the mutable nature of lists in Python. [code] >>> anima ...

Python: split string method and examples

So you are looking to break up a string into smaller strings (in an array if you are coming from a PHP / JavaScript background) based on a delimiter or character. Python provides a very straightforward and easy function to do that. The function is called split, it returns a list as the result (you really don't want to a Python array for this one) and here are some examples. Examples 1 to 3 are to be tri ...

Python: check if a character or substring is in a string

Let me start with a little history about myself. I have been developing on the Web for more than five years now - in PHP. Yes, in goddamn PHP! I had been exposed to Python much earlier, but for some strange reason I never made the effort to learn it or use it. If I had learnt Python earlier, I wouldn't be struggling to to check if a substring exists in a string or not today. On the brighter side, I realize what a beauti ...