Lists and Slices
Lists: indices, slices, the built-in len, sum, max, min functions and sort.
The list is Python's main data structure: an ordered collection of values. Indices start at zero; negative indices count from the end: a[-1] is the last element.
Slices are Python's signature trick: a[1:4] — the elements at indices 1, 2, 3; a[::-1] — the list in reverse order.
Python
Indices, slices and appending elements
Lists come with ready-made functions that in C++ you would write as loops: len (length), sum, max and min, sorted (a sorted copy), the a.sort() method (in-place sort).
Don't overuse them mindlessly: in an interview or a problem review you may be asked to write a maximum search by hand — so below are both versions.
Python
Maximum: with the built-in function and by hand. Enter: 5, then 1 3 5 2 4
Task: read a list of numbers and print it sorted in descending order (hint: sorted(a, reverse=True)).
Then solve the attached problem "Maximum in an Array" and mark the lesson as completed.