Python Sorting Data

preview_player
Показать описание
In this Python tutorial, we will go over how to sort lists using sort() and sorted(), reverse sort, sort a list of tuples, use a sort key, sort data objects created from a class, how to use the operator module itemgetter(), attrgetter() functions, sort based on multiple elements (i.e.-sort by grade, then by name, etc.), sort a dictionary, sort imported csv file data.

Examples for sorting dictionary by key or value below:
import operator
planets_with_moons = {'Mercury': 0, 'Venus': 0, 'Earth': 1, 'Mars': 2, 'Jupiter': 67, 'Saturn': 62, 'Uranus': 27, 'Neptune': 14}
# examples using lambda function and operator module itemgetter
# 0 sorts dictionary by key, 1 sorts dictionary by value
# .items() converts dictionary to list of tuples
# dict() converts back to dictionary
Рекомендации по теме
Комментарии
Автор

Excellent. Just what I was looking for. Thanks.

ratonmagico
Автор

very good explanations but unfortunately let down by the quality of the recording.

jsllsj
welcome to shbcf.ru