Steven D'Aprano wrote:
> On Sun, 26 Nov 2006 00:25:13 -0800, hollowspook wrote:
>
> > Hi, there
> >
> > a = range(100)
> >
> > if I want to use No 7, 11, 56,90 in a, then the only way I do is [a[7],
> > a[11], a[56], a[90]].
> > Is there any other way?
>
> a = [7, 11, 56, 90]
>
> Are those numbers
hollowspook wrote:
> how about indexing 1-7, 10
> [range(1:8),10] will generate [[1, 2, 3, 4, 5, 6, 7], 10], instead of
> [1, 2, 3, 4, 5, 6, 7, 10]
>>> range(1,8)+[10]
[1, 2, 3, 4, 5, 6, 7, 10]
--
Under construction
--
http://mail.python.org/mailman/listinfo/python-list
Thanks, bearophile.
range(1, 8) + [10] is great!
"[EMAIL PROTECTED] 写道:
"
> hollowspook:
> > how about indexing 1-7, 10
> > [range(1:8),10] will generate [[1, 2, 3, 4, 5, 6, 7], 10], instead of
> > [1, 2, 3, 4, 5, 6, 7, 10]
>
> (Note that range(1:8) is a syntax error).
>
> You can join and extend
hollowspook:
> how about indexing 1-7, 10
> [range(1:8),10] will generate [[1, 2, 3, 4, 5, 6, 7], 10], instead of
> [1, 2, 3, 4, 5, 6, 7, 10]
(Note that range(1:8) is a syntax error).
You can join and extend lists as you like:
>>> range(1, 8) + [10]
[1, 2, 3, 4, 5, 6, 7, 10]
See also the list.a
Thanks, John
how about indexing 1-7, 10
[range(1:8),10] will generate [[1, 2, 3, 4, 5, 6, 7], 10], instead of
[1, 2, 3, 4, 5, 6, 7, 10]
"John Machin 写道:
"
> hollowspook wrote:
> > Hi, there
> >
> > a = range(100)
> >
> > if I want to use No 7, 11, 56,90 in a, then the only way I do is [a[7],
> >
On Sun, 26 Nov 2006 00:25:13 -0800, hollowspook wrote:
> Hi, there
>
> a = range(100)
>
> if I want to use No 7, 11, 56,90 in a, then the only way I do is [a[7],
> a[11], a[56], a[90]].
> Is there any other way?
a = [7, 11, 56, 90]
Are those numbers supposed to be in some sort of series? They
hollowspook wrote:
> Hi, there
>
> a = range(100)
>
> if I want to use No 7, 11, 56,90 in a, then the only way I do is [a[7],
> a[11], a[56], a[90]].
> Is there any other way?
>
I presume a = range(100) is just an indication that a is a list -- the
literal answer to your question as asked is simpl