Example
Sorting and Reversing Lists
Methods sort() and reverse() for ordering list elements.
10 results
Example
Methods sort() and reverse() for ordering list elements.
Challenge
…the cargo manifest heaviest first with a key function and reverse=True.
Article Mini projects
…by 6 and collect the remainders. Those remainders, read in reverse order, give you the base-6 number. def decimal_to_base6(decimal_number): if decimal_number == 0: return "0" digits = [] # We'll…
Challenge
…readings from highest to lowest, in place, with sort(reverse=True) , then print the three highest with a slice: Highest three: [455.2, 430.1, 412.5] Don't store what sort() gives back.
Challenge
…a type error, a wrong key, an index out of range and a reversed decision. Read each error to fix the four that crash, then find the one that runs but gives the wrong answer.
Challenge
…add undo, which takes the last change off the history and reverses it.
Quiz
…and modification , append, insert and pop and sorting and reversing lists . After this one, try the Python For Loop Quiz or the Python While Loop Quiz . What does this code print? What does this code…
Example
Accessing individual characters and text fragments. Zero-based indexing in Python.
Challenge
…kg (3%) spares: 2.4 kg (2%) sorted(totals, key=totals.get, reverse=True) gives the categories ordered by their totals. sum(totals.values()) is the whole load.
Quiz
…len() Indexing and slicing, including negative indexes and reversing a string Case methods such as upper() and title() , and why a method does not change the original string Checking text with in , ==…