我有一个for循环来处理来自输入的数据 当它找到开始索引行的条件时,如何在它之前减去两行
# this is the data sample
Candra Insley
Ivette Ralston
Florentina Bohon
Natalie Underhill
Shoshana Risinger
Melony Hulsey
Klara Warren
Corrina Broderick
Susana Vitti
Susy Seidman
Chris Deen
Mason Nebel
Tawanda Riccio
Shameka Schmitmeyer
Robert Longacre
Floria Padro
Julius Gelman
Kyung Barnard
Freida Manville
Wendy Bolduc
这是密码
status = request.form['data']
status = str(status).split('\n')
for i in status:
if len(i) < 2:
continue
print i
data = i[0]
condition = 'Shameka Schmitmeyer'
if condition in data:
print 'found it'
condition = ''
i -= 2 # here it will subtract the current data index 2 it will go back two line to this "Mason Nebel" data and start the for from it and continue
print data
#output it should be like
Candra Insley
Ivette Ralston
Florentina Bohon
Natalie Underhill
Shoshana Risinger
Melony Hulsey
Klara Warren
Corrina Broderick
Susana Vitti
Susy Seidman
Chris Deen
Mason Nebel
Tawanda Riccio
found it
Shameka Schmitmeyer
这里是它继续时的样子
Mason Nebel
Tawanda Riccio
Shameka Schmitmeyer
Robert Longacre
Floria Padro
Julius Gelman
Kyung Barnard
Freida Manville
Wendy Bolduc
如何用它来做呢
或
或
希望这是清楚明白的
这是don buy while loop可以购买的
输出
相关问题 更多 >
编程相关推荐