Python论坛  - 讨论区

标题:[python-chinese] 同样的元素随机产生新的list

2007年04月08日 星期日 17:41

linda.s samrobertsmith在gmail.com
星期日 四月 8 17:41:28 HKT 2007

Hi,
有一个 a list: [2,5,8,0,1,7],
如何用同样的元素随机产生新的list
如:
[5,2,8,0,1,7]
[8,0,7,1,5,2]
多谢!!!
Linda

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2007年04月08日 星期日 17:53

东子 hydonlee在gmail.com
星期日 四月 8 17:53:46 HKT 2007

貌似random.sample正好满足你的需要
import random

a = [2,5,8,0,1,7]
random.sample(a, len(a))

2007/4/8, linda. s <samrobertsmith at gmail.com>:
>
> Hi,
> 有一个 a list: [2,5,8,0,1,7],
> 如何用同样的元素随机产生新的list
> 如:
> [5,2,8,0,1,7]
> [8,0,7,1,5,2]
> 多谢!!!
> Linda
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese




-- 
只要人间真情在, 何必在意路泥泞
时风日下,和谐需要靠暴力达到!!!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://python.cn/pipermail/python-chinese/attachments/20070408/cd20ac62/attachment.html 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2007年04月08日 星期日 22:20

Yunfeng Tao taoyfeng在gmail.com
星期日 四月 8 22:20:36 HKT 2007

random.shuffle

2007/4/8, linda. s <samrobertsmith在gmail.com>:
> Hi,
> 有一个 a list: [2,5,8,0,1,7],
> 如何用同样的元素随机产生新的list
> 如:
> [5,2,8,0,1,7]
> [8,0,7,1,5,2]
> 多谢!!!
> Linda
> _______________________________________________
> python-chinese
> Post: send python-chinese在lists.python.cn
> Subscribe: send subscribe to python-chinese-request在lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2007年04月09日 星期一 08:51

miaozhaozhao20 miaozhaozhao200在163.com
星期一 四月 9 08:51:23 HKT 2007

是的。这个函数可以。我刚想回复呢。呵呵   
在2007-04-08,"东子" <hydonlee at gmail.com> 写道:
貌似random.sample正好满足你的需要
import random
a = [2,5,8,0,1,7]
random.sample(a, len(a))
2007/4/8, linda. s <samrobertsmith at gmail.com >:Hi,
有一个 a list: [2,5,8,0,1,7],
如何用同样的元素随机产生新的list
如:
[5,2,8,0,1,7]
[8,0,7,1,5,2]
多谢!!!
Linda
_______________________________________________
python-chinese
Post: sendpython-chinese at lists.python.cn
Subscribe: send subscribe topython-chinese-request at lists.python.cn
Unsubscribe: send unsubscribe to  python-chinese-request at lists.python.cn
Detail Info:http://python.cn/mailman/listinfo/python-chinese
--
只要人间真情在, 何必在意路泥泞
时风日下,和谐需要靠暴力达到!!!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://python.cn/pipermail/python-chinese/attachments/20070409/70440a0c/attachment.html 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2007年04月09日 星期一 11:14

shhgs shhgs.efhilt在gmail.com
星期一 四月 9 11:14:26 HKT 2007

random.shuffle

On 4/8/07, miaozhaozhao20 <miaozhaozhao200在163.com> wrote:
> 是的。这个函数可以。我刚想回复呢。呵呵
>
>
>
>
> 在2007-04-08,"东子" <hydonlee在gmail.com> 写道:
>
>
> 貌似random.sample正好满足你的需要
> import random
>
> a = [2,5,8,0,1,7]
> random.sample(a, len(a))
>
>
> 2007/4/8, linda. s <samrobertsmith在gmail.com >:
> > Hi,
> > 有一个 a list: [2,5,8,0,1,7],
> > 如何用同样的元素随机产生新的list
> > 如:
> > [5,2,8,0,1,7]
> > [8,0,7,1,5,2]
> > 多谢!!!
> > Linda
> > _______________________________________________
> > python-chinese
> > Post: send python-chinese在lists.python.cn
> > Subscribe: send subscribe to
> python-chinese-request在lists.python.cn
> > Unsubscribe: send unsubscribe to
> python-chinese-request在lists.python.cn
> > Detail Info:
> http://python.cn/mailman/listinfo/python-chinese
>
>
>
> --
> 只要人间真情在, 何必在意路泥泞
> 时风日下,和谐需要靠暴力达到!!!
>
> ________________________________
>  远离垃圾邮件?免费帮你过滤98%的垃圾邮件! www.126.com
> _______________________________________________
> python-chinese
> Post: send python-chinese在lists.python.cn
> Subscribe: send subscribe to
> python-chinese-request在lists.python.cn
> Unsubscribe: send unsubscribe to
> python-chinese-request在lists.python.cn
> Detail Info:
> http://python.cn/mailman/listinfo/python-chinese
>

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2007年04月09日 星期一 13:04

东子 hydonlee在gmail.com
星期一 四月 9 13:04:57 HKT 2007

Y , random.shuffle更快。

在07-4-9,shhgs <shhgs.efhilt at gmail.com> 写道:
>
> random.shuffle
>
> On 4/8/07, miaozhaozhao20 <miaozhaozhao200 at 163.com> wrote:
> > 是的。这个函数可以。我刚想回复呢。呵呵
> >
> >
> >
> >
> > 在2007-04-08,"东子" <hydonlee at gmail.com> 写道:
> >
> >
> > 貌似random.sample正好满足你的需要
> > import random
> >
> > a = [2,5,8,0,1,7]
> > random.sample(a, len(a))
> >
> >
> > 2007/4/8, linda. s <samrobertsmith at gmail.com >:
> > > Hi,
> > > 有一个 a list: [2,5,8,0,1,7],
> > > 如何用同样的元素随机产生新的list
> > > 如:
> > > [5,2,8,0,1,7]
> > > [8,0,7,1,5,2]
> > > 多谢!!!
> > > Linda
> > > _______________________________________________
> > > python-chinese
> > > Post: send python-chinese at lists.python.cn
> > > Subscribe: send subscribe to
> > python-chinese-request at lists.python.cn
> > > Unsubscribe: send unsubscribe to
> > python-chinese-request at lists.python.cn
> > > Detail Info:
> > http://python.cn/mailman/listinfo/python-chinese
> >
> >
> >
> > --
> > 只要人间真情在, 何必在意路泥泞
> > 时风日下,和谐需要靠暴力达到!!!
> >
> > ________________________________
> >  远离垃圾邮件?免费帮你过滤98%的垃圾邮件! www.126.com
> > _______________________________________________
> > python-chinese
> > Post: send python-chinese at lists.python.cn
> > Subscribe: send subscribe to
> > python-chinese-request at lists.python.cn
> > Unsubscribe: send unsubscribe to
> > python-chinese-request at lists.python.cn
> > Detail Info:
> > http://python.cn/mailman/listinfo/python-chinese
> >
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese




-- 
只要人间真情在, 何必在意路泥泞
时风日下,和谐需要靠暴力达到!!!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://python.cn/pipermail/python-chinese/attachments/20070409/43dc1917/attachment.htm 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

如下红色区域有误,请重新填写。

    你的回复:

    请 登录 后回复。还没有在Zeuux哲思注册吗?现在 注册 !

    Zeuux © 2025

    京ICP备05028076号