2006年04月04日 星期二 23:06
limodou,您好! 谢谢。 还有一个问题请教。比如有一个LIST,我必须使用for ll in l这样的格式进行处理,当其中的一个符合某种条件的时候, 就把表中所有符合该条件的项目都修改数值,(还有一种要求,就是把符合条件的项目都从列表中剔除), 该怎么做呢? for ll in l: if .......: pass else: #符合条件,把LIST中其它的符合条件的项目都修改一下。 或者: for ll in l: if .......: pass else: #把这个项目从l中删除。 再次感谢 在 2006-04-04 22:44:00 您写道: >On 4/4/06, cry <zyqmail at tom.com> wrote: >> python,您好! >> 如何修改一个list里的值呢?比如把下列的值大于5的都变成0。 >> >> l=[1,2,3,4,5,6,7,8,9] >> for ll in l: >> if ll > 5: >> ll = 0 >> >> 好象不行,怎么做比较合适呢?受C的影响太严重。:( >> > >map(lambda x:x<5 and x or 0, l) > >-- >I like python! >My Blog: http://www.donews.net/limodou >My Django Site: http://www.djangocn.org >NewEdit Maillist: http://groups.google.com/group/NewEdit >_______________________________________________ >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 致 礼! cry zyqmail at tom.com
2006年04月05日 星期三 01:25
修改
for i, x in enumerate(a):
if x ...:
pass
else:
a[i] = 10
删除
r = []
for x in a:
if x ...:
pass
else:
r.append(x)
a = r
On 4/4/06, cry <zyqmail at tom.com> wrote:
>
> limodou,您好!
>
> 谢谢。
>
> 还有一个问题请教。比如有一个LIST,我必须使用for ll in l这样的格式进行处理,当其中的一个符合某种条件的时候,
> 就把表中所有符合该条件的项目都修改数值,(还有一种要求,就是把符合条件的项目都从列表中剔除),
> 该怎么做呢?
>
> for ll in l:
> if .......:
> pass
> else:
> #符合条件,把LIST中其它的符合条件的项目都修改一下。
>
> 或者:
> for ll in l:
> if .......:
> pass
> else:
> #把这个项目从l中删除。
>
> 再次感谢
>
>
>
> 在 2006-04-04 22:44:00 您写道:
> >On 4/4/06, cry <zyqmail at tom.com> wrote:
> >> python,您好!
> >> 如何修改一个list里的值呢?比如把下列的值大于5的都变成0。
> >>
> >> l=[1,2,3,4,5,6,7,8,9]
> >> for ll in l:
> >> if ll > 5:
> >> ll = 0
> >>
> >> 好象不行,怎么做比较合适呢?受C的影响太严重。:(
> >>
> >
> >map(lambda x:x<5 and x or 0, l)
> >
> >--
> >I like python!
> >My Blog: http://www.donews.net/limodou
> >My Django Site: http://www.djangocn.org
> >NewEdit Maillist: http://groups.google.com/group/NewEdit
> >_______________________________________________
> >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
>
> 致
> 礼!
>
> cry
> zyqmail at tom.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
>
--
http://www.flyaflya.com powered by pygame+python
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060405/11c6a6c0/attachment.html
Zeuux © 2025
京ICP备05028076号