Sorting in python

One of the strong python feature is its data structure,list and dictionary give you the power to play with your data in versatile way.
Also have some methods which are needed by python programmer in day to day code work.

One of the basic and strong method is sorting.
Example is:

>>>a = [1,2,3,6,3,4]
>>>print a
[1, 2, 3, 3, 4, 6]

Another efficient feature that we can use key while doing the sorting.Its like:

>>> a = [1,2,3,4]
>>> sorted(a, reverse=True)
[4, 3, 2, 1]

Another parameter we can use during sorted() is “key”

>>>a = ['e','f','a','g']
>>> sorted(a, key=str.lower)
['a', 'e', 'f', 'g']

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.