Python - Create list with numbers between 2 values?

How would I create a list with values between 2 values I put in? For example, following list is generated for values between 11 and 16:

    list = [11, 12, 13, 14, 15, 16]

Use range. In Python 2.x it returns a list so all you need is,

    >>> range(11, 17)
    [11, 12, 13, 14, 15, 16]

In Python 3.x it's a iterator so you need to convert it to a list,

    >>> list(range(11, 17))
    [11, 12, 13, 14, 15, 16]

Note : Second number is exclusive so here it needs to be 16+1 = 17

EDIT:

To response to the question about incrementing by 0.5 the easiest option would probably be to use numpy's arange,

    >>> numpy.arange(11, 17, 0.5)
    array([ 11. ,  11.5,  12. ,  12.5,  13. ,  13.5,  14. ,  14.5,  15. ,
            15.5,  16. ,  16.5])

From: stackoverflow.com/q/18265935

Back to homepage or read more recommendations: