Products
Features
YouTube Video Summarizer
Summarize YouTube videos
Web & PDF Highlighter
Highlight web pages & PDFs
Chat with PDF
Ask any PDF questions with AI
Ask AI Clone
Chat with your highlights & memories
Audio Transcriber
Transcribe audio files to text
Glasp Reader
Read and highlight articles
Kindle Highlight Export
Export your Kindle highlights
Idea Hatch
Hatch ideas from your highlights
Integrations
Obsidian Plugin
Notion Integration
Pocket Integration
Instapaper Integration
Medium Integration
Readwise Integration
Snipd Integration
Hypothesis Integration
Apps & Extensions
Chrome Extension
Safari Extension
Edge Add-ons
Firefox Add-ons
iOS App
Android App
Discover
Discover
Ideas
Discover new ideas and insights
Articles
Curated articles and insights
Books
Book recommendations by great minds
Posts
Essays and notes from readers
Quotes
Inspiring quotes collection
Videos
Curated videos and summaries
Explore Glasp
Glasp Story
How we grew from 0 to 3 million users
Glasp Newsletter
Weekly insights and updates
Glasp Talk
Interview series with great minds
Glasp Blog
Latest news and articles
Glasp Use Cases
Learn how others use Glasp
Build & Support
Glasp API
Access Glasp's API for developers
MCP Connector
Connect Glasp to Claude & ChatGPT
Community
Glasp Reddit Community
Students
Student discount and benefits
FAQs
Frequently Asked Questions
AboutPricing
DashboardLog inSign up

How to Sort a Python Dictionary By Value or Key!

69.7K views
•
June 10, 2013
by
sentdex
YouTube video player
How to Sort a Python Dictionary By Value or Key!

TL;DR

Learn how to order a Python dictionary using a hackish method, either by sorting it by key or by value.

Transcript

hello and welcome to another Python tutorial in this tutorial we're going to be discussing how to order a python dictionary um just as an aside fundamentally a python dictionary actually has no uh order so to speak and so if you sometimes you try to like look this problem up online you might find people tell you that that is simply not possible um ... Read More

Key Insights

  • 🤩 Python dictionaries have no inherent order, but they can be sorted by key or value.
  • 🤩 Sorting a dictionary by key uses the sorted function with a lambda function that extracts the key.
  • 😒 Sorting a dictionary by value uses the same approach but extracts the value instead.
  • 👂 When a dictionary is sorted, it is converted into an array with a list inside it, not an ordered dictionary.
  • 👂 Order is useful when creating a list from a dictionary or for specific purposes, but not for creating an ordered dictionary.
  • 🪈 Ordering a dictionary is possible but requires a hackish approach.
  • 🤩 The hackish approach involves using the sorted function and lambda functions to extract and sort either the keys or values.

Install to Summarize YouTube Videos and Get Transcripts

Explore YouTube Video Summarizer or Get YouTube Transcript Extractor

Questions & Answers

Q: Can a Python dictionary be ordered?

By default, a Python dictionary has no order. However, there are ways to order a dictionary by either sorting it by key or by value.

Q: How can I sort a dictionary by key in Python?

To sort a dictionary by key, you can use the sorted function with the key parameter set to a lambda function that extracts the key. This will return a sorted array with a list of key-value pairs.

Q: What is the difference between sorting a dictionary by key and by value?

Sorting a dictionary by key arranges it based on the keys, either alphabetically or numerically. Sorting by value arranges the dictionary based on the values associated with the keys.

Q: Can an ordered dictionary be created in Python?

No, an ordered dictionary cannot be created in Python. The only way to order a dictionary is by sorting it, which converts it into an array with a list inside it.

Summary & Key Takeaways

  • Python dictionaries have no inherent order, but there are ways to sort them. One method is by sorting them by key, which arranges the dictionary alphabetically or numerically based on the keys.

  • Another method is by sorting them by value, which arranges the dictionary based on the values associated with the keys.

  • It's important to note that when the dictionary is sorted, it is converted into an array with a list inside it, not an ordered dictionary.


Read in Other Languages (beta)

English

Share This Summary 📚

Summarize YouTube Videos and Get Video Transcripts with 1-Click

Download browser extensions on:

Try YouTube Summary with ChatGPT & Claude or YouTube Transcript Generator

Explore More Summaries from sentdex 📚

Python: How to Graph the Chaikin Money Flow Trading Indicator in Matplotlib thumbnail
Python: How to Graph the Chaikin Money Flow Trading Indicator in Matplotlib
sentdex
How to Parse Twitter Data Using Python Effectively thumbnail
How to Parse Twitter Data Using Python Effectively
sentdex
Python: How to Program the Chaikin Money Flow Trading Indicator thumbnail
Python: How to Program the Chaikin Money Flow Trading Indicator
sentdex
Python Generator Functions for massive Performance Improvements with Lists thumbnail
Python Generator Functions for massive Performance Improvements with Lists
sentdex
Parsing XML - Go Lang Practical Programming Tutorial p.11 thumbnail
Parsing XML - Go Lang Practical Programming Tutorial p.11
sentdex
How to Train a Chatbot Using TensorFlow and Python thumbnail
How to Train a Chatbot Using TensorFlow and Python
sentdex

Summarize YouTube Videos and Get Video Transcripts with 1-Click

Download browser extensions on:

Try YouTube Summary with ChatGPT & Claude or YouTube Transcript Generator

Apps & Extensions

  • Chrome Extension
  • Safari Extension
  • Edge Add-ons
  • Firefox Add-ons
  • iOS App
  • Android App

Key Features

  • YouTube Video Summarizer
  • Web & PDF Summarizer
  • Web & PDF Highlighter
  • Chat with PDF
  • Ask AI Clone
  • Audio Transcriber
  • Glasp Reader
  • Kindle Highlight Export
  • Idea Hatch

Integrations

  • Obsidian Plugin
  • Notion Integration
  • Pocket Integration
  • Instapaper Integration
  • Medium Integration
  • Readwise Integration
  • Snipd Integration
  • Hypothesis Integration

More Features

  • APIs
  • MCP Connector
  • Blog & Post
  • Embed Links
  • Image Highlight
  • Personality Test
  • Quote Shots
  • Open Graph Checker

Company

  • About us
  • Our Story
  • Blog
  • Community
  • FAQs
  • Job Board
  • Newsletter
  • Pricing
Terms

•

Privacy

•

Guidelines

© 2026 Glasp Inc. All rights reserved.