472,371 Members | 1,588 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,371 software developers and data experts.

Hi, I am getting the following errorTypeError: sort() takes nokeyword arguments

Hi all,
I am using python version 2.3.in a program ,
I have called the sort function.Wherein,
a.sort(reverse=True)
is giving the following error:

TypeError: sort() takes no keyword arguments.

It works in python 2.4,What can be the alternative in python 2.3

Thanks ,
Gaurav

Oct 17 '08 #1
2 2447
gaurav kashyap wrote:
Hi all,
I am using python version 2.3.in a program ,
I have called the sort function.Wherein,
a.sort(reverse=True)
is giving the following error:

TypeError: sort() takes no keyword arguments.

It works in python 2.4,What can be the alternative in python 2.3

Thanks ,
Gaurav
You could try:
>>a.sort()
a = a[::-1]
Oct 17 '08 #2
Aidan <aw****@gmail.comwrote:
gaurav kashyap wrote:
>Hi all,
I am using python version 2.3.in a program ,
I have called the sort function.Wherein,
a.sort(reverse=True)
is giving the following error:

TypeError: sort() takes no keyword arguments.

It works in python 2.4,What can be the alternative in python 2.3

Thanks ,
Gaurav

You could try:
>a.sort()
a = a[::-1]

You could, but you should also be aware that there is a subtle difference.
The 'reverse' keyword argument gives a stable reverse sort, sorting and
then reversing something is not stable. e.g.
>>data = [(1, 'zzz'), (1, 'abc'), (2, 'def'), (1, 'pqr'), (2, 'jkl')]
a = data[:]
a.sort(lambda p,q: cmp(p[0],q[0]), reverse=True)
a
[(2, 'def'), (2, 'jkl'), (1, 'zzz'), (1, 'abc'), (1, 'pqr')]
>>a = data[:]
a.sort(lambda p,q: cmp(p[0],q[0]))
a[::-1]
[(2, 'jkl'), (2, 'def'), (1, 'pqr'), (1, 'abc'), (1, 'zzz')]
--
Duncan Booth http://kupuguy.blogspot.com
Oct 17 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Paul MG | last post by:
Hi Is there a simple general way of getting the keys out of a map? Or a vector of pairs? My problem seems to be that the pair<> type returned by iterating through either has no methods to...
20
by: Xah Lee | last post by:
Sort a List Xah Lee, 200510 In this page, we show how to sort a list in Python & Perl and also discuss some math of sort. To sort a list in Python, use the “sort” method. For example: ...
3
by: winkatl1213 | last post by:
Hello, I am working with comtypes to interface Microsoft's DirectShow library. First, I found a Type Library on the internet that was created for accessing DirectShow from .NET. It seems that...
7
by: mooon33358 | last post by:
I have a little problem with implementing a recursive merge sort I have to use a function mergesort that takes 3 arguments - an array, its size, and an help array(i.e mergesort(int array, int...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.