我想实现一个代码,该代码将在给定当前迭代内的条件的情况下重置字典上的迭代。它应该看起来像这样
<body>
<div class="container">
<header class="Team Sky">
<img src="img/TeamSkyLogo.png" alt="Team Sky Logo" style="float: left;">
<nav class="site-navigation">
<ul class="clearfix navmenu">
<li><a href="#">shop</a></li>
<li><a href="#">checkout</a></li>
<li><a href="#">video</a></li>
<li>
<form class="search">
<input id="search" type="text" name="search" placeholder="search">
</form>
</li>
</ul>
</nav>
<div id="HeaderBike" class="HeaderBike"> <--- open never closed
<div>
<h1>Team Sky</h1>
<P>the road to yellow</P>
</div>
</header> <--- this was after div that goes next
</div>
变量如下:
我必须使用(有序)字典。有没有人有一些好的想法来重置我的迭代条件?
谢谢你们提前与我思考!
编辑:解决方案结果非常平凡:递归调用if语句中的函数,以便整个函数将使用新变量运行。代码如下:
for index in range(1, max_index):
for phrase in rules:
for constituents in rules[phrase]:
if mem_list[-index:] == constituents:
del mem_list[-index:]
mem_list.append(phrase)
# reset all of the three for loops
答案 0 :(得分:2)
从中创建一个函数,并返回mem_list
def asd():
for index in range(1, max_index):
for phrase in rules:
for constituents in rules[phrase]:
if mem_list[-index:] == constituents:
del mem_list[-index:]
mem_list.append(phrase)
# reset all of the three for loops
return mem_list
some_list = asd()