Skip to main content
deleted 1 character in body
Source Link

This is not great design. For starters it would be less efficient to enumerate the range.

The code you provided would produce the same result as this:

d = {}
for i in range(4):
    d[i] = i ** 2

I would recommend trying variations out in the python console. The advantage your code has over this is that it sets up i and v so if you did want to modify either of these in different ways it could make it clear, especially for maths students ( II have seen a whole host of unpythonic things which they do.)

This is not great design. For starters it would be less efficient to enumerate the range.

The code you provided would produce the same result as this:

d = {}
for i in range(4):
    d[i] = i ** 2

I would recommend trying variations out in the python console. The advantage your code has over this is that it sets up i and v so if you did want to modify either of these in different ways it could make it clear, especially for maths students ( I have seen a whole host of unpythonic things which they do.

This is not great design. For starters it would be less efficient to enumerate the range.

The code you provided would produce the same result as this:

d = {}
for i in range(4):
    d[i] = i ** 2

I would recommend trying variations out in the python console. The advantage your code has over this is that it sets up i and v so if you did want to modify either of these in different ways it could make it clear, especially for maths students (I have seen a whole host of unpythonic things which they do)

Source Link

This is not great design. For starters it would be less efficient to enumerate the range.

The code you provided would produce the same result as this:

d = {}
for i in range(4):
    d[i] = i ** 2

I would recommend trying variations out in the python console. The advantage your code has over this is that it sets up i and v so if you did want to modify either of these in different ways it could make it clear, especially for maths students ( I have seen a whole host of unpythonic things which they do.