problem about list indexing

2006-11-26 Thread hollowspook
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? Thanks in advance. -- http://mail.python.org/mailman/listinfo/python-list

Re: problem about list indexing

2006-11-26 Thread 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], 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 simply [7,

Re: problem about list indexing

2006-11-26 Thread Steven D'Aprano
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

Re: problem about list indexing

2006-11-26 Thread hollowspook
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], a[11], a[56],

Re: problem about list indexing

2006-11-26 Thread bearophileHUGS
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.append

Re: problem about list indexing

2006-11-26 Thread hollowspook
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 lists as you

Re: problem about list indexing

2006-11-26 Thread ZeD
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

Re: problem about list indexing

2006-11-26 Thread John Machin
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 supposed to be in