怎么样删除python list里面的","
2013-08-31 05:49:21 +08:00
brucebot
比如有这么一段,想要删除",",这应该怎么来处理?
[{"title": [["", " ", " Funny CAT = Funny cats in water, EPIC", " ", " ", " ", " Very Funny Cats!!", " ", " ", " ", " Cute Funny Cats Fail Compilation - 2013", " ", " ", " ", " 100 Funny Cats 2", " ", " ", " ", " Cats are terribly afraid of the water", " ", " ", " ", " NEW very funny cats!The Best!", " ", " ", " ", " The Best of funny and sweet Cats 2012 NEW", " ", " ", " ", " Funny Cats part 2 (WAR CATS!!)", " ", " ", " ", " Funny cats XD", " ", " ", " ", " Funny Cats Compilation (Hilarious)", " ", " ", " ", " 20 Minutes of Funny Cats!!!!", " ", " ", " ", " Funny Cats Compilation 2013 - Funny Cats Compilation", " ", " ", " ", " Funny Cats In Funny Cats Video When Toast Attacks", " ", " ", " ", " FUNNY ANIMALS VIDEO - FUNNY CATS STONED..", " ", " ", " ", " Funny Dogs & Cats Unusual - Ugly? Beauty is in the eye of the beholder.", " ", " ", " ", " Funny Cats Video Compilations-", " ", " ", " ", " Funny Cats. Little fail of Kitten", " ", " ", " ", " Funny CAT = Kitten miscalculates jump funny video cats", " ", " ", " ", " Funny Cats - Two kittens Playing with a Ball", " ", " ", " ", " Funny Cats Episode 1", " ", " "]]},
5 条回复
avichen
2013-08-31 06:22:42 +08:00
list.remove(",")
当然先要判断一下是否存在",",然后再remove。
ahxxm
2013-08-31 06:22:53 +08:00
[item for item in list if item != ","]
9hills
2013-08-31 06:31:32 +08:00
你们都没理解lz想要做什么,不是说list的内容里有',' , 而是lz想把list 打印出来,不含','。。
Python list拼接推荐用join,很好理解
String.join(list),就是将list的各个元素以字符串String(可以为空)拼接起来
lz的例子显然是这样的
''.join(['sdfdsf','sdfsdf',' ', 'sdfdsf'])
brucebot
2013-08-31 08:17:17 +08:00
我是用
video['title'] = [''.join(app.select('./li/div/h3//text()').extract_unquoted()).split('\n')]
在抓取网页头的时候得到这组数据的,如果不用split('\n')则会有很多个无用的\n,但是我又要保证每两个\n之间的字符串与其他的字符串分开,因为生成的是json,我需要与另一条命令
video['link'] = app.select('./li/div/h3/a/@src').extract
生成的json串对应起来
@
9hills @
ahxxm @
avichen
detailyang
2013-08-31 09:00:33 +08:00
生成json最好用extract[0],不然json.loads会无法解析....同时记得判断数据是否存在,
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
https://www.v2ex.com/t/80828
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.