built in list generator?

afrobeard afrobeard at gmail.com
Tue May 13 18:48:38 EDT 2008


range(50,100,2) returns a list of numbers starting from 50 and less
than 100 with a step size of 2.

list() takes any iterable datatype and converts it into a list.

e.g. list((1, 2, 3)) would return [1,2,3]
& list([1, 2]) would return [1,2]

In this case there is no point of calling range within list since the
output of range is already a list.

Note list(xrange(50,100,2)) would have made sense if range didnt exist
and you needed a list, but since range does exist, I dont see the
point.

Diez is right when he says to use list to iterate, because creating a
big list just for the sake of iteration would be a terrible waste of
space.

On May 14, 1:16 am, "Diez B. Roggisch" <de... at nospam.web.de> wrote:
> globalrev schrieb:
>
> > if i want  a list with all numbers between x and y is there a way to
> > do this with an inbult function.
>
> > i mean i can always construct a function to do this but is there
> > soemthing like:
>
> > nbrs = list(range(50,100, 2))
>
> range *does* that. use xrange if all you want is to iterate.
>
> Diez




More information about the Python-list mailing list