Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8302113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:12:13+00:00 2026-06-08T17:12:13+00:00

Ideally sort() function is superb example of Polymorphism . In case of sort() function,

  • 0

Ideally sort() function is superb example of Polymorphism. In case of sort() function, you can sort almost anything with it.

In [27]: b
Out[27]: [3, 4, 5, 6]

In [28]: b = ['a','b',5,6,None]

In [29]: b.sort()

In [30]: b
Out[30]: [None, 5, 6, 'a', 'b']

In [31]: b = ['a','b',23,'c',None,5j]

In [32]: b.sort()
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/home/dubizzle/webapps/django/dubizzle/<ipython-input-32-fc40da74ac51> in <module>()
----> 1 b.sort()

TypeError: no ordering relation is defined for complex numbers

but it seems that in case of imaginary numbers sort() function fails. Please note that I am getting this error TypeError: no ordering relation is defined for complex numbers.

So My questions are

  1. Where exactly this ordering is defined ? How sort() function works internally ?
  2. Is there any purpose for leaving this ordering relation for complex numbers or it just left out similarly as we have no power operator in c language ( A mistake).
  3. How do we sort the imaginary (complex) numbers in python basically ? Do we have a pythonic way to do this ?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T17:12:14+00:00Added an answer on June 8, 2026 at 5:12 pm

    In mathematical terms, the set of complex numbers cannot be a totally ordered set; defining an order for them requires you to provide a key by which they can be ordered. This depends on what you want: do you want to order them by their real values?

    b.sort(key=lambda complex_: complex_.real)
    

    By their imaginary values?

    b.sort(key=lambda complex_: complex_.imag)
    

    By their magnitude?

    b.sort(key=lambda complex_: sqrt(complex_.real**2 + complex_.imag**2))
    

    However you want to order them, you specify a function to compare elements using the key keyword.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ideally I want a function something like the following (this example doesn't compile): void
How do I prevent duplicate entries into a list, and then ideally, sort that
Ideally something I can plug and play pretty readily an quickly that supports GeoCoding
Season's greetings! I have a function that prints out the contents of a char**
I've been playing around trying to get a function that will sort a selection
How can I do some sort of mass recode of a dataset in R
Is there some sort of alternative toolchain or language for Android, which can generate
Ideally I just want a list of strings, or Hashmap String,String : List<String> =
Ideally I would like intellij to work with this but just getting them to
Ideally, I'd like a module or library that doesn't require superuser access to install;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.