作者chickdcing (小鸡)
看板Python
标题[问题] 请问要怎麽从string list中抓出整数
时间Sat Nov 15 14:36:26 2014
请问一下
同标题
要怎麽从list中 找出整数
我想要实现 如果我的list是这样
[usa, aaa, bbb, ccc, 0, 40,....]
我想要抓出 0 -----> i+1:0
请问我应该要怎麽写这判断式
我现在是使用 for xxx in 'usa' 这种去找
但是我抓不到integer
如果有违反版规的话 请告诉我我会删掉
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 140.112.41.129
※ 文章网址: http://webptt.com/cn.aspx?n=bbs/Python/M.1416033388.A.076.html
1F:推 flarehunter: "我想要抓出 0 -----> i+1:0" 这是什麽意思? 11/15 14:47
2F:→ chickdcing: 意思是说我要抓出这个数字 放在新的list中 11/15 14:47
3F:→ chickdcing: 如果是第i项抓到0 放到新的list中变i+1:0 11/15 14:48
4F:→ secondsee: blist = [e for e in alist if type(e)==int] 11/15 14:52
5F:→ chickdcing: 如果数字是random呢? 就是我无法确定是哪些的话 11/15 14:53
6F:推 goldflower: 不太懂 上面的方法是不是random有差吗@@ 11/16 00:57
7F:→ chickdcing: 我懂了 哈哈哈 谢谢大家 11/16 01:20
8F:→ panpass: [u"{}:{}".format(i+1, n) for i, n in enumerate(\ 12/03 03:00
9F:→ panpass: yourlist) if n.isdigit() and u"." not in n] 12/03 03:03