Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Searching
Sorting – sort()
Sorting – sorted()
Sorting – reverse() and reversed()
Summary
15. Summary

Instruction

Okay, it's time to wrap things up! First, a quick review of what we've learned:

  1. To check if an item is present in a data structure, use the in operator:
    letters_set = {'a', 'b', 'c', 'd', 'e'}
    if 'c' in letters_set:
      print('Found!')
    
  2. To sort a list in place, use the .sort() method:
    names_list = ['Kate', 'John', 'Paul', 'Anne']
    names_list.sort()
    
  3. To sort a list in descending order, use the reverse argument:
    names_list = ['Kate', 'John', 'Paul', 'Anne']
    names_list.sort(reverse=True)
    
  4. To get a sorted copy, use the .sorted() method:
    words_list = ['come', 'tell', 'say', 'go', 'run']
    list_sorted_ascending = words_list.sorted()
    list_sorted_descending = words_list.sorted(reverse=False)
    
  5. To reverse the order of elements in place, use the .reverse() method:
    numbers_list = [1, 2, 3, 4, 5, 6, 7]
    numbers_list.reverse()
  6. To get a reversed copy of a list, use a for loop and the reversed() function:
    numbers_list = [1, 2, 3, 4, 5, 6, 7]
    reversed_list = []
    for item in reversed(numbers_list):
      reversed_list.append(item)
    

Good! Are you ready for a short quiz?

Exercise

Click Next exercise to continue.