How to Browse a List in Python

In this tutorial we will learn how to browse and display the elements of an array in Python.

Browse a python array with the for in

You can simply use the for in to be able to read all the elements of an array.

equipements = ["Tablet", "Smartphone", "Computer"]

for x in equipements:
print(x)

Execution:

Tablet
Smartphone
Computer

Browse using the while()

The while can be used to browse in the same way as the for in.

list = [1, 2, 3, 4, 5, 6]

i = 0

# browse with the while
while i < len(lst):
print(list[i])
i = i+1

Runtime:

1
2
3
4
5

Browse using the range()

method range() can be combined with the for method to display the elements of an array in python.

range (start, end, pitch))

  • start: This parameter is to set the index of the beginning.
  • end; This parameter is to set the end index of the sequence to be displayed.
  • not(optional): the difference between each value for the sequence to be generated.

The function range() generates a sequence of integers from start to finish. The end value is not included in the final sequence.

list = [3, 6, 32, 96, 43, 22]
for i in range(len(list)):
print(lst[i])

Runtime:

3
6
32
96
43
22

Browse using the list in comprehension

In a single line, It is possible to browse the table.

list=[3, 6, 7, 9, 6]
[print(x) for x in list]

Execution

3
6
7
9
6

Browse using Numpy

It is possible to generate an array of integers in Python with the function numpy.arange() which creates a sequence of integers from 1 to n, then browse with the method numpy.nditer(array).

numpy.arange(start, end, pitch)

  • beginning: clue of the beginning.
  • end; End Index.
  • not(optional): The difference between each value for the sequence to be generated.

import numpy as np

n = np.arange(11)

for x in np.nditer(n):
print(x)

Runtime:

1
2
3
4
5
6
7
8
9
10
11