Tutorial B2 o.a. loop teamplates

4 important questions on Tutorial B2 o.a. loop teamplates

To really copy a list in Python, use a slice for the full length of the original:


def square_all (p_arr):
    arr = p_arr[:]   # copy elements
    for i in range(len(arr)):
        arr[i] = arr[i] * arr[i]
    return arr

anders verwijs je alleen naar hetzelfde, naar een positie waar het is opgeslagen.

Aliasing (a,b,c)

a = [0, 1, 2]
b = a
a[1] = 3
a   # [0, 3, 2] as expected
b   # [0, 3, 2] perhaps not expected
c = [3, 4, 5]
a = c
a   # [3, 4, 5]  -- now alias of c
b   # [0, 3, 2]  -- no more aliasing with a

“maximum template” and “minimum template”

for determining the largest or smallest value from the series.
  • Higher grades + faster learning
  • Never study anything twice
  • 100% sure, 100% understanding
Discover Study Smart

The summing template adds all values from a series together:


sum = 0
for i in range(len(arr)):
    elem = arr[i]
    sum += elem
#answer in variable: sum

The question on the page originate from the summary of the following study material:

  • A unique study and practice tool
  • Never study anything twice again
  • Get the grades you hope for
  • 100% sure, 100% understanding
Remember faster, study better. Scientifically proven.
Trustpilot Logo