foo = open('words.txt').readlines()
[k.rstrip() for k in foo if k.rstrip() != '']
我想重复使用修改过的键,就像那样
[k.rstrip() for k in foo if k != '']
这可能吗?你知道吗
# input (words.txt)
# this will be just some lines with one or more words separated by space.
# there will be no *special* case or anything
foo bar
baz
bar baz waz
# expected output
>>> ['foo bar', 'baz', 'bar baz waz']
这样做:
看起来你想过滤掉空行,你可以这样做:
相关问题 更多 >
编程相关推荐