2014-03-30 103 views
0

我有两个用Python打开的json文件。我想做一些事情,如果一个条件不满意,我可以跳过当前的元素并继续下一个。我的代码如下所示:跳过列表元素 - Python

t_a = first json file 
t = second json file 
for token in t_a 
    if token in t 
    #do something 
    if token not in t 
    #skip the current token and move on to the next one 

我的问题与最后一步进来。我是新来的蟒蛇,我不知道如何跳过当前元素

+3

['continue'](http://docs.python.org/2/ tutorial/controlflow.html#break-and-continue-statements-and-else-clause-on-loops)语句? – thefourtheye

+0

您还需要将这两个文件加载到内存中。由于你是新手代码,我建议你应该在这里发布整个代码。另外,请看@thefourtheye建议的continue语句。 –

+0

所以沿着token = test_list.skip()的行继续? – carebear

回答

3

只需使用continue

t_a = first json file 
t = second json file 
for token in t_a 
    if token in t: 
    #do something 
    else: 
    #skip the current token and move on to the next one 
     continue 
    #do something else here