擅长:python、mysql、java
<p>您可以使用列表理解来读取文件并仅获取包含单词的行,例如:</p>
<pre><code>with open('save.txt', 'r') as f:
uinput = input("input here: ")
found = [line.rstrip() for line in f if uinput.lower() in line.lower()]
if found:
print('Found in these lines: ')
print('\n'.join(found))
else:
print('Not found.')
</code></pre>
<p>如果只想打印链接,可以使用:</p>
<pre><code>found = [line.rstrip().split(',')[1] for line in f if uinput.lower() in line.lower()]
</code></pre>