Wolfram: Create Flat List (Range)

By Xah Lee. Date: . Last updated: .

Range

Range
  • range[max]
  • range[min, max]
  • range[min, max, step]

return a flat list.

Like Python range but more powerful. Argument needs not be integer.

Range[5]
(* {1, 2, 3, 4, 5} *)
(* min to max *)
Range[4, 8]
(* {4, 5, 6, 7, 8} *)
(* step of 0.5 *)
Range[1, 3, 0.5]
(* {1., 1.5, 2., 2.5, 3.} *)

(* If step is not evenly divisible by max, the result does not contain max *)
Range[1, 3, 0.7]
(* {1., 1.7, 2.4} *)

(* symbolic step *)
Range[1, 3, 1/2]
(* {1, 3/2, 2, 5/2, 3} *)

(* negative step *)
Range[1, -1,  -0.5]
(* {1., 0.5, 0., -0.5, -1.} *)
(* any arg can be symbolic *)
Range[0, 3 Pi,  Pi/2]
(* {0, Pi/2, Pi, (3*Pi)/2, 2*Pi, (5*Pi)/2, 3*Pi} *)

Wolfram. List Operations, and Loop, Iteration, Recursion