Wednesday, 28 August 2013

The Power of Python

"Power is PYTHON's mistress. It has worked too hard and taken too many risks at her conquest to allow anyone to take her away from it."

Truth be spoken , it is indeed true. But without going on how's and when Python achieved this let's focus on Why? This post is dedicated to the things that make Python GODLIKE _/\_ . The image below defines what I am trying to say .

 
  Hmmm, that was something :P . Now let me some python power aside from no brackets and semicolons.

''' To swap two numbers ''' 
 >>> a,b = b,a

''' To find the longest line in file  '''
 >>>  max(open('test.txt'), key=len) 

''' To sum the digits in an unsigned integer '''
  >>> sum(map(int, str(n))) 

''' Transposing a matrix: '''
>>> l = [[1, 2, 3], [4, 5, 6]]
>>> zip(*l)
  [(1, 4), (2, 5), (3, 6)]

''' Ever used if-condition like this '''
 >>> x = 3 if (y == 1) else 2

''' To extract only unique elemnts from a list(array) '''
  >>> list(set(list_name)

''' The amazing Regular Expression library '''       
 >>> import re
>>> a=" hello world this 58 re is 69 "
>>> re.findall('\d+',a)
 ['58','69']

 


Hmm, that was something again . Normal C , JAVA would require you to write large lines of codes to perform those functions. And this is only a start , when you dive in the deep sea of python and its libraries you will find amazing modules and functions and your task will be only a few words away.

Enjoy PYTHON. Cheers.
 

 
     

No comments:

Post a Comment