<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/lexicographical-ordering-in-python-mglpoah8p" -->

---
title: Lexicographical ordering in Python | daily.dev
description: Lexicographical ordering in Python explains how strings, tuples, lists, and all sequences are compared element-by-element, similar to alphabetical ordering....
canonical: https://daily.dev/posts/lexicographical-ordering-in-python-mglpoah8p
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Lexicographical ordering in Python | daily.dev
og:description: Lexicographical ordering in Python explains how strings, tuples, lists, and all sequences are compared element-by-element, similar to alphabetical ordering....
og:url: https://daily.dev/posts/lexicographical-ordering-in-python-mglpoah8p
og:image: https://api.daily.dev/og/posts/mGlPoAh8p.png
og:image:alt: Lexicographical ordering in Python
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Lexicographical ordering in Python

**[Planet Python](https://daily.dev/sources/planetpython)** · 6 min read · 0 upvotes · 0 comments

## Summary

Lexicographical ordering in Python explains how strings, tuples, lists, and all sequences are compared element-by-element, similar to alphabetical ordering. Python uses Unicode code points to determine character order, meaning uppercase letters sort before lowercase. The comparison works by finding the first differing element; if one sequence is a prefix of another, the shorter one is considered less. This behavior is practically useful for multi-key sorting: placing values in tuples in priority order lets Python's built-in sort handle hierarchical ordering automatically, such as sorting alumni by year, then last name, then first name.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.pythonmorsels.com/lexicographical-ordering/>

## Similar posts on daily.dev

- [Sorting a Python Dictionary: Values, Keys, and More Quiz – Real Python](https://daily.dev/posts/sorting-a-python-dictionary-values-keys-and-more-quiz-real-python-bo7hfzshm) · Real Python · 2 upvotes · 0 comments
- [All iteration is the same in Python](https://daily.dev/posts/all-iteration-is-the-same-in-python-kmgraqtz3) · Planet Python · 1 upvotes · 0 comments
- [Python Dictionary: The Smart Way to Store and Access Data](https://daily.dev/posts/python-dictionary-the-smart-way-to-store-and-access-data-qwan7sxsu) · Medium · 0 upvotes · 0 comments

---

Tags: [#python](https://daily.dev/tags/python), [#data-structures](https://daily.dev/tags/data-structures)

[View this post on daily.dev](https://daily.dev/posts/lexicographical-ordering-in-python-mglpoah8p)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Lexicographical ordering in Python","url":"https://daily.dev/posts/lexicographical-ordering-in-python-mglpoah8p","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/lexicographical-ordering-in-python-mglpoah8p"},"datePublished":"2026-02-25T16:46:33.315Z","dateModified":"2026-02-25T16:46:56.574Z","description":"Lexicographical ordering in Python explains how strings, tuples, lists, and all sequences are compared element-by-element, similar to alphabetical ordering....","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/a6739a5553e860d44b5e44f69881f140?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/a6739a5553e860d44b5e44f69881f140?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Planet Python","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Planet Python","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/eac3cc584cb043b5a242d13752bd3d0c","url":"https://daily.dev/sources/planetpython"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/lexicographical-ordering-in-python-mglpoah8p","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"python,data-structures","timeRequired":"PT6M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Planet Python","item":"https://daily.dev/sources/planetpython"},{"@type":"ListItem","position":3,"name":"Lexicographical ordering in Python"}]}
```

