['/N/98445.html', '/N/98439.html', '/HomeV2/Banner/Records?model=A1&name=A1&url=https%3A%2F%2Fwww.jiemodui.com%2FKe%2F97539.html%3Ffrom%3Djmd004&flag=3a6f8321cf5ca56b13fd4a40a9474246', '/N/98441.html', '/N/98436.html', '/N/98435.html', '/N/98433.html', '/N/98434.html', '/HomeV2/Banner/Records?model=A3&name=A3&url=https%3A%2F%2Fwww.jiemodui.com%2FA%2F98137%3F%3Dxxl3&flag=90e994d56cd13c6b3201012bc988873a', '/N/98432.html', '/N/98431.html', '/N/98430.html', '/N/98429.html', '/N/98427.html', '/N/98426.html', '/N/98421.html', '/N/98416.html', '/N/98420.html', '/N/98407.html', '/N/98419.html', '/N/98411.html', '/N/98406.html']
这里我想保留 /N/98445.html 类似的格式,把 很长的 /HomeV2 那两个很长的从列表中删除,我想到的办法就是遇到这个字符串 pass 然后 重新构造一个列表添加,因为可能这个带 /HomeV2 字符串不在这个位置 有没有不需要重新构造一个列表直接在原来的列表删除这两个有 /HomeV2 的长字符串
1
ranleng 2018-07-26 21:03:04 +08:00
filter(lambda x:not x.startswith("/HomeV2"), lst)
|
3
KeatingSmith 2018-07-26 23:27:17 +08:00
for i in range(len(source_list)):
if source_list[I].startswith('/HomeV2'): source_list.remove(i) |
5
noqwerty 2018-07-29 04:58:37 +08:00
[x for x in url_list if "/HomeV2" not in x]
|
6
frmongo 2018-07-31 14:10:35 +08:00
如下
a= [.......上面那个 list] for ele in a: if ele.startwith("/HomeV2") or len(ele)>13: a.remove(ele) print "remove elements from a [%s]" % ele else: pass print a |