Lesson 17 of 34

List Methods: Add, Remove, Sort

9 min 25 XP

append() adds to the end, insert() adds at a position, remove() deletes a value, and pop() takes out the last item.

Example: edit me and press Run

Output Loading Python (first time takes a few seconds)
Press Run to see the result here.

For number lists, sum(), max() and min() are very handy. sort() orders from small to large; sort(reverse=True) does the opposite.

Example: edit me and press Run

Output Loading Python (first time takes a few seconds)
Press Run to see the result here.

To read many numbers from one line: input().split() gives a list of strings; convert each one to int.

Example: edit me and press Run

Output Loading Python (first time takes a few seconds)
Press Run to see the result here.

Challenge

+25 XP

One line of space-separated numbers is given (see the Input box). Print the difference between the largest and the smallest (max - min).

Output Loading Python (first time takes a few seconds)
Press Run to see the result here.