【发布时间】:2011-05-05 22:40:30
【问题描述】:
我想做这样的事情,但是在 python 中:
select * from [list] where [element at index n] = 'hello'
到目前为止,我有这个
cells = [' ','hello',' ',' ',' ',' ',' ',' ',' ']
emptySpots = []
for s in range(len(cells)):
if cells[s] == 'hello':
emptySpots.append(s)
这给了我一个包含“你好”的单元格的索引列表,但我敢打赌,有一种更直接(pythonesque)的方式来做到这一点。
最好是一个单行,它只返回单元格中等于“”的元素数量的计数。
【问题讨论】: