def linspace(start, stop, num):
    return [(stop*i + start*(num-i)) / num
            for i in range(num+1)]


import collections
import collections.abc

class linspace(collections.abc.Sequence):
    def __init__(self, start, stop, num):
        self.start, self.stop, self.num = start, stop, num
    def __len__(self):
        return self.num
    def __getitem__(self, i):
        if i >= self.num:
            raise IndexError('linspace object index out of range')
        return (self.stop*i + self.start*(self.num-i-1))/(self.num-1)

if __name__ == '__main__':
    print(list(linspace(1, 2, 5)))

Fix off-by-one error, make it lazy
Fix off-by-one error, make it lazy

- def linspace(start, stop, num):
-     return [(stop*i + start*(num-i)) / num
-             for i in range(num+1)]
  
+ import collections
+ import collections.abc
+ 
+ class linspace(collections.abc.Sequence):
+     def __init__(self, start, stop, num):
+         self.start, self.stop, self.num = start, stop, num
+     def __len__(self):
+         return self.num
+     def __getitem__(self, i):
+         if i >= self.num:
+             raise IndexError('linspace object index out of range')
+         return (self.stop*i + self.start*(self.num-i-1))/(self.num-1)
+ 
+ if __name__ == '__main__':
+     print(list(linspace(1, 2, 5)))
+ 
Fix off-by-one error, make it lazy
## Code Before:
def linspace(start, stop, num):
    return [(stop*i + start*(num-i)) / num
            for i in range(num+1)]

## Instruction:
Fix off-by-one error, make it lazy
## Code After:

import collections
import collections.abc

class linspace(collections.abc.Sequence):
    def __init__(self, start, stop, num):
        self.start, self.stop, self.num = start, stop, num
    def __len__(self):
        return self.num
    def __getitem__(self, i):
        if i >= self.num:
            raise IndexError('linspace object index out of range')
        return (self.stop*i + self.start*(self.num-i-1))/(self.num-1)

if __name__ == '__main__':
    print(list(linspace(1, 2, 5)))
