【发布时间】:2018-06-05 11:35:43
【问题描述】:
我正在寻找一种解决方案来订购我的循环选择。 My problem is that when is select the rows, these aren't sorted.所以我想找到所有匹配的行并处理它们,然后根据下一个关键词找到下一个匹配的行。我想要的另一个方面是我想首先找到所有匹配的行,然后基于下一个关键词找到所有匹配的行。最后我想指出,我不想将结果附加到不同的变量中,因为我有很多关键字。
这是我的问题的一个简单示例:
key_word=['one', 'two']
list=['one1', 'one2', 'two1', 'two2', 'two3', 'one3']
for i in list:
for word in key_word:
if (word in i):
print (i)
我的输出:
one1
one2
two1
two2
two3
one3
我想要的输出:
one1
one2
one3
two1
two2
two3
【问题讨论】:
标签: python python-3.x loops sorting