By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,525 Members | 1,667 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,525 IT Pros & Developers. It's quick & easy.

Doubt regarding sorting functions

P: n/a
Dear All,

I am new to Python. I am in need of
some sorting functions (eg) numerical sorting
functions and alphapetical sorting functions.
I have searched through net But I cannot
find any regarding this so If anyone know
regarding this. Kindly mail me as early as possible

with regards
PRabahr

__________________________________________________ ______________________
Yahoo! India Matrimony: Find your life partner online
Go to: http://yahoo.shaadi.com/india-matrimony
Jul 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On Mon, 11 Apr 2005 05:50:11 +0100 (BST), praba kar <pr*********@yahoo.co.in> wrote:
Dear All,

I am new to Python. I am in need of
some sorting functions (eg) numerical sorting
functions and alphapetical sorting functions.
I have searched through net But I cannot
find any regarding this so If anyone know
regarding this. Kindly mail me as early as possible

with regards
PRabahr


Frankly, your claim to has "searched through the net" is not believable,
unless you are not using a search engine such as google, in which case
go to google.com (assuming you know how to do that) and type in something
like

sorting site:python.org

and press enter. The "site:python.org" will limit the search to
what is available on the python.org site, which has a high concentration
of Python-relevant information.

Perhaps this will help someone avoid a seemingly helpless or lazy post like yours.

BTW, a request to "mail me as early as possible" is more likely
to get favorable consideration if you explain why you can't
monitor the newsgroup postings for a reply.

Regards,
Bengt Richter
Jul 18 '05 #2

P: n/a
Basically you can sort after you put your data in your list:
L = [1.2,1.23,4.5,2]
L.sort()
print L

L = ["a","c","b","A","C","B"]
L.sort()
print L

Result:
[1.2, 1.23, 2, 4.5]
['A', 'B', 'C', 'a', 'b', 'c']

#------------------------------------------------------------
remember in character the "A" has lower ascii value then "a"

To model this as a function you just need this code for two of them:

def funcSort(myList):
result = myList[:]
result.sort()
return result

Use of this function:
L = [1.2,1.23,4.5,2]
res1 = funcSort(L)
print res1

L = ["a","c","b","A","C","B"]
res1 = funcSort(L)
print res1
Best Regards,
Pujo

Jul 18 '05 #3

P: n/a
aj****@gmail.com wrote:
def funcSort(myList):
result = myList[:]
result.sort()
return result


In Python 2.4, funcSort is called sorted:

py> sorted([1.2,1.23,4.5,2])
[1.2, 1.23, 2, 4.5]
py> sorted(["a","c","b","A","C","B"])
['A', 'B', 'C', 'a', 'b', 'c']

STeVe
Jul 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.