⇤ ← Revision 1 as of 2009-01-16 10:54:47
Size: 2077
Comment:
|
Size: 1947
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 87: | Line 87: |
创建 by -- ZoomQuiet [[[DateTime(2009-01-16T10:54:47Z)]]] ||<^>[[PageComment2]]||<^>[:/PageCommentData:PageCommentData]''|| |
秒杀 list 中的空item
filter(lambda)
Heroboy <[email protected]> reply-to [email protected] to [email protected] date Fri, Jan 9, 2009 at 15:30 subject [CPyUG:76474] Re: 怎么用快速把一个list中的空item去除?
aa=filter(lambda x:x=='',aa);
列表推导
smallfish <[email protected]> reply-to [email protected] to [email protected] date Fri, Jan 9, 2009 at 15:31 subject [CPyUG:76475] Re: 怎么用快速把一个list中的空item去除?
1. aa = [for i in aa if i != ''] 2. bb = set(aa) cc = [for i in bb if i != '']
khsing <[email protected]> reply-to [email protected] to [email protected] date Fri, Jan 9, 2009 at 18:20
[i for i in list if i]
LaiYonghao <[email protected]> reply-to [email protected] to [email protected] date Fri, Jan 9, 2009 at 18:48
突然想起,楼主的空行的意思估计是指由空白符组成的行。 那就得用 lines = [line for line in f if not line.isspace()]
itertools.ifiter()
Heroboy <[email protected]> reply-to [email protected] to [email protected] date Fri, Jan 9, 2009 at 16:45 subject [CPyUG:76494] Re: 怎么用快速把一个list中的空item去除?
for i in itertools.ifiter(f,lambda x:x): pass
filter()
Liu Qishuai <[email protected]> reply-to [email protected] to python-cn`CPyUG`华蟒用户组 <[email protected]> date Fri, Jan 9, 2009 at 17:06 subject [CPyUG:76495] Re: 怎么用快速把一个list中的空item去除?
a = filter(None, a)
反馈