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

  • SEARCH
  • Home
  • 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 8732957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:32:36+00:00 2026-06-13T09:32:36+00:00

I noticed a piece of code recently directly comparing two lists of integers like

  • 0

I noticed a piece of code recently directly comparing two lists of integers like so:

a = [10,3,5, ...]
b = [5,4,3, ...,]
if a > b:
     ...

which seemed a bit peculiar, but I imagined it would return True if all of list_a‘s elements are larger then list_b‘s and False if each element is equal or list_b‘s elements are larger then list_a‘s. So I tested it:

>>> a=[3,3,3,3]
>>> b=[4,4,4,4]
>>> a>b
False
>>> b>a
True

Ok that works. As does:

>>> b = [1,1,1,1]
>>> a = [1,1,1,1]
>>> a>b
False
>>> b>a
False

but when it gets more fuzzy:

>>> a=[1,1,3,1]
>>> b=[1,3,1,1]
>>> a>b
False
>>> b>a
True

or:

>>> a=[1,3,1,1]
>>> b=[1,1,3,3]
>>> a>b
True
>>> b>a
False

the results are a bit stranger. What is python actually doing? It seems that it’s returning the result in favour of the first list in which the left most element is greater then the corresponding?

  • 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-13T09:32:37+00:00Added an answer on June 13, 2026 at 9:32 am

    From Comparing Sequences and Other Types in the Python tutorial:

    The comparison uses lexicographical ordering: first the first two items are compared, and if they differ this determines the outcome of the comparison; if they are equal, the next two items are compared, and so on, until either sequence is exhausted.

    See also the Wikipedia article about lexicographical order.

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

Sidebar

Related Questions

Recently I wrote a piece of C# code utilizing a Lambda expression: var dynMenu
I have this piece of code I'm trying to get to display but no
I have the following piece of code, which I want to make parallel in
I am getting an error in a piece of code in our framework which
I have noticed this piece of code: FileInfo[] files =new DirectoryInfo(@C:\).GetFiles(); What is the
While running through a piece of code for performance tuning, i noticed that the
I recently found this piece of JavaScript code: Math.random() * 0x1000000 << 0 I
I write network application which communicates via Linux TCP socket. Recently I've noticed send
I noticed this piece of code in using CodeIgniter database migrations: $this->migrations->verbose AND print
I was looking at the Java reflection classes and noticed this piece of code.

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.