Python - Create list with numbers between 2 values? -


how create list values between 2 values put in? example, following list generated values between 11 , 16:

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

use range. in python 2.x returns list need is,

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

in python 3.x it's iterator need convert list,

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

note: second number exclusive here needs 16+1 = 17

edit:

to response question incrementing 0.5 easiest option 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]) 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -