Reputation:
newarray = [x + 0.5 for x in range(1, 10)]
this code will give me following result:
newarray
[1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5]
Instead of adding 0.5 with x I want to increase my x by 0.5 for each 1 increment of x. The output suppose to be
newarray=[0.5,1,1.5,2,2.5......5.5].
Keep in mind that my range must be fix in 1 to 10. What can be better approach to make that?
Upvotes: 0
Views: 47
Reputation: 968
[0.5 * x for x in range(1, 12)]
Will do the thing, I'm afraid generating that array with range(1, 10)
is impossible
Upvotes: 1