Python 从txt文件中 读取数据存入 列表 并进行搜索查询

txt 格式如下 词与词之间 是空格隔开的
第一行:你好 我 他 是 恩 ......
第二行: 对 啊 额 那 就是 .....
.......N多行

假设 列表为 a[i][j]
想要搜索: 我
输出: a[0][1]

# coding: UTF-8

blist = []
split_char = ' '
with open('b.txt', 'r') as bf:
    blist = [b.strip().split(split_char) for b in bf]

word = '我'
print repr(word)
for bl in blist:
    print bl
    if word in bl:
        print 'blist[%d][%d]' % (blist.index(bl),bl.index(word))

来自:求助得到的回答
温馨提示:答案为网友推荐,仅供参考
第1个回答  2015-05-06
txt文件read出来 按照“\n”分成几行,再把每一行按照空格分开,存到一个列表里就行了。
搜索 就用index吧。追问

能稍微 帮忙敲几行代码嘛?

相似回答