Course Hive
Search

Welcome

Sign in or create your account

Continue with Google
or
Python SORTING is easy (sort of) ๐Ÿ”€
Play lesson

Python tutorial for beginners ๐Ÿ - Python SORTING is easy (sort of) ๐Ÿ”€

4.0 (0)
8 learners

What you'll learn

This course includes

  • 14.3 hours of video
  • Certificate of completion
  • Access on mobile and TV

Summary

Keywords

Full Transcript

#pythonprogramming #pythontutorial #python 00:00:00 intro 00:00:25 lists 00:01:40 tuples 00:03:20 dictionaries 00:08:12 objects # SORTING IN PYTHON .sort() or sorted() # Lists[], Tuples(), Dictionaries{"":""}, Objects # ---------- LISTS ---------- fruits = ["banana", "orange", "apple", "coconut"] # fruits.sort() # fruits.sort(reverse=True) print(fruits) # ---------- TUPLES ---------- fruits = ("banana", "orange", "apple", "coconut") # fruits = tuple(sorted(fruits)) # fruits = tuple(sorted(fruits, reverse=True)) print(fruits) # ---------- DICTIONARIES ---------- fruits = { "banana": 105, "apple": 72, "orange": 73, "coconut": 354 } # fruits = dict(sorted(fruits.items())) # fruits = dict(sorted(fruits.items(), key=lambda item: item[0], reverse=True)) # fruits = dict(sorted(fruits.items(), key=lambda item: item[1])) # fruits = dict(sorted(fruits.items(), key=lambda item: item[1], reverse=True)) print(fruits) # ---------- OBJECTS ---------- class Fruit: def __init__(self, name, calories): self.name = name self.calories = calories def __repr__(self): return f"{self.name}: {self.calories}" fruits = [Fruit("banana", 105), Fruit("apple", 72), Fruit("orange", 73), Fruit("coconut", 354)] # fruits = sorted(fruits, key=lambda fruit: fruit.name) # fruits = sorted(fruits, key=lambda fruit: fruit.name, reverse=True) # fruits = sorted(fruits, key=lambda fruit: fruit.calories) # fruits = sorted(fruits, key=lambda fruit: fruit.calories, reverse=True) print(fruits)

Course Hive

Continue this lesson in the app

Install CourseHive on Android or iOS to keep learning while you move.

Related Courses

FAQs

Course Hive
Download CourseHive
Keep learning anywhere