473,624 Members | 2,261 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Wherei n,
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 2544
gaurav kashyap wrote:
Hi all,
I am using python version 2.3.in a program ,
I have called the sort function.Wherei n,
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.c omwrote:
gaurav kashyap wrote:
>Hi all,
I am using python version 2.3.in a program ,
I have called the sort function.Wherei n,
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(lamb da p,q: cmp(p[0],q[0]), reverse=True)
a
[(2, 'def'), (2, 'jkl'), (1, 'zzz'), (1, 'abc'), (1, 'pqr')]
>>a = data[:]
a.sort(lamb da 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
7727
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 bind to to get the .first or .second elements. That seems to me to be a major oversight - so I am assuming I must be making one! For instance, imagine I want to use eg accumulate, to add up all the keys in a
20
4053
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: li=;
3
3298
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 DirectShow only comes with IDL files and no type library. This got me started.
7
576
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 size, int temp] . I have to use only the temp array for the sorting, I cant use two help arrays for the sorting, and I cant change the signature of the function. also have a merge function that takes 5 arguments - left array and its size, right...
0
8233
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
8170
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8619
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8334
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7158
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5561
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4173
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2604
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1482
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.