El grupo al cual envías entradas es un
grupo Usenet . Si envías mensajes a este grupo, cualquier usuario de Internet podrá ver tu dirección de correo electrónico
Tu respuesta no se ha enviado.
Tu entrada se ha publicado correctamente.
Grupos de noticias: cn.bbs.comp.lang.python
De:
l... @newsmth.net-SPAM.no (lac)
Fecha: 19 Nov 2009 10:17:08 GMT
Local: Jue 19 nov 2009 05:17
Asunto: Re: list怎么按长度切割呢
I used len(L)>>4 for list of thousands of elems
adapt the number of pieces to your own program, e.g. as a function argument
【 在 inference (What do I do now, Ellie?) 的大作中提到: 】 : 标 题: Re: list怎么按长度切割呢 : 发信站: 水木社区 (Fri Oct 30 07:57:53 2009), 转信 : : : 【 在 lac (lac) 的大作中提到: 】 : : 标 题: Re: list怎么按长度切割呢 : : 发信站: 水木社区 (Fri Oct 30 06:00:15 2009), 转信 : : : : # L is a list : : num, pieces, upper = len(L), len(L)>>4, 0 # around 2^4 pieces : pieces是0,后面不会被执行,执行也会出现除零错误。 : : for k in range(pieces): : : lower, upper = upper, upper + (num + k) // pieces : : # ADD CODE HERE, e.g. R.append(L[lower:upper]) : : : : 【 在 thom (emerge a new world...) 的大作中提到: 】 : : : 比如 list = [1, 2, 3, 4, 5, 6, 7, 8, 9] : : : 想分成[[1, 2, 3], [4, 5, 6], [7, 8, 9]] : : : 不想慢慢切了,思维现在缰住了。囧 : : : ................... : : : : -- : : : : [m [1;32m※ 来源:·水木社区 newsmth.net·[FROM: 211.99.222.*] [m : : : -- : : [m [1;32m※ 来源:·水木社区 newsmth.net·[FROM: 202.120.58.*] [m
--
[m [1;37m※ 来源:·水木社区 newsmth.net·[FROM: 211.99.222.*] [m
No dispones del permiso necesario para enviar entradas.
Grupos de noticias: cn.bbs.comp.lang.python
De:
xenos <xeno... @gmail.com>
Fecha: Fri, 20 Nov 2009 04:02:40 -0800 (PST)
Local: Vie 20 nov 2009 07:02
Asunto: Re: list怎么按长度切割呢
是要3个3个分组吗?
>>> ls = [1,2,3,4,5,6,7,8,9] >>> for i in xrange(0,len(ls),3):
ls[i:i+3]
[1, 2, 3] [4, 5, 6] [7, 8, 9]
On 11月19日, 上午10时17分, l
... @newsmth.net-SPAM.no (lac) wrote:
> I used len(L)>>4 for list of thousands of elems
> adapt the number of pieces to your own program, e.g. as a function argument
> 【 在 inference (What do I do now, Ellie?) 的大作中提到: 】 > : 标 题: Re: list怎么按长度切割呢 > : 发信站: 水木社区 (Fri Oct 30 07:57:53 2009), 转信 > : > : > : 【 在 lac (lac) 的大作中提到: 】 > : : 标 题: Re: list怎么按长度切割呢 > : : 发信站: 水木社区 (Fri Oct 30 06:00:15 2009), 转信 > : : > : : # L is a list > : : num, pieces, upper = len(L), len(L)>>4, 0 # around 2^4 pieces > : pieces是0,后面不会被执行,执行也会出现除零错误。 > : : for k in range(pieces): > : : lower, upper = upper, upper + (num + k) // pieces > : : # ADD CODE HERE, e.g. R.append(L[lower:upper]) > : : > : : 【 在 thom (emerge a new world...) 的大作中提到: 】 > : : : 比如 list = [1, 2, 3, 4, 5, 6, 7, 8, 9] > : : : 想分成[[1, 2, 3], [4, 5, 6], [7, 8, 9]] > : : : 不想慢慢切了,思维现在缰住了。囧
No dispones del permiso necesario para enviar entradas.