23
Lesson 6 of 44

Arrays

Explore lists in Python, an essential concept in programming that allows you to work with structured sets of data. You will learn how to manipulate and use lists to solve a variety of problems and tasks in programming. This lesson equips you with the necessary skills to work with lists and solve complex programming problems in Python. Enhance your programming skills through practical exercises and expand your abilities in managing structured data.

  • 9 theory articles
  • 14 practice exercises
Start lesson

Fundamentals concepts 9

Lists: Python's arrays

Until now each variable stored a single value. When you need to store many (10 marks, 1000 numbers), creating a variable for each…

Theory
Read more

Adding, removing and changing elements

Lists can grow and shrink while the program runs. These are the methods you will use most.

Theory
Read more

Reading data into a list and looping over it

Almost all list exercises follow the same scheme: read values into a list, go through it and show the result.

Theory
Read more

Searching, filtering and calculating with lists

Once the data is stored, the usual thing is to ask questions about it.

Theory
Read more

Two-dimensional lists (matrices)

A list can contain other lists. With that you represent tables, boards and drawings: each inner list is a row.

Theory
Read more

Sorting lists and bubble sort

Sorting a list is one of the most studied operations in programming. Python does it for you with sort() and sorted() , but…

Theory
Read more

Menu programs, statistics and common mistakes

The last exercise of the lesson, Mathematical statistics , brings everything together: a list that grows, a menu that repeats…

Theory
Read more

Advanced slicing and sorting

Slices list[start:stop:step] can be used with negative indexes, steps and omitted limits, both to read and to assign or delete…

Theory
Read more

List aliases and copies

Assigning a list to another variable does not copy it : both variables point to the same object, and changing one changes the…

Theory
Read more

Practice exercises 14

Reverse order array

Create a Python program that asks the user for 5 integers, stores them in a list and displays them in reverse order.

Exercise Medium
Solve it

Search an array of integers

Create a Python program to search for values in a list of integers. Follow these steps:

Exercise Medium
Solve it

Search even numbers

Write a Python program that asks the user for 10 integers. Then, store these numbers in a list and display only the even numbers.

Exercise Medium
Solve it

Search positive and negative numbers

Write a Python program that prompts the user to enter 10 real numbers and displays the arithmetic mean of positive and negative…

Exercise Medium
Solve it

Banner command on Unix

Create a Python program that emulates the Unix banner command. Internally, use a list of strings (a table of characters) to store…

Exercise Medium
Solve it

Bubble sort

Create a Python program that prompts the user for 10 integers and sorts them using the bubble sort algorithm.

Exercise Medium
Solve it

Two-dimensional array

Create a Python program that asks the user for the scores of 10 students, divided into 2 groups of 5 students each. Store the…

Exercise Medium
Solve it

Two-dimensional array of chars

Create a Python program that builds a two-dimensional list of characters with 20 rows and 70 columns, fills it with the letter X…

Exercise Medium
Solve it

Mathematical statistics

Create a Python program that generates mathematical statistics. The program stores up to 1000 decimal numbers in a list and shows…

Exercise Medium
Solve it

On-screen circumference

Create a Python program that generates the drawing of a circle on the screen, dividing it into 360 equidistant points. Use the…

Exercise Medium
Solve it

Rotate a list

Rotating a list k positions to the right means the last k elements move to the front. Slicing lets you do it without loops.

Exercise Medium
Solve it

Remove duplicates keeping the order

Turning a list into a set removes repeats but loses the order . To keep it you must remember which items have already been seen.

Exercise Medium
Solve it

Merge two sorted lists

If two lists are already sorted, they can be merged into a single sorted one by walking through both with two indexes, without…

Exercise Hard
Solve it

Sort by several criteria

sort accepts a key function that returns a tuple : it sorts by the first element and, on a tie, by the second, and so on. To…

Exercise Hard
Solve it