在Python中跳过列表中的元素

0 投票
1 回答
1253 浏览
提问于 2025-04-18 00:31

我有两个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

我的问题出现在最后一步。我刚学Python,不太确定怎么跳过当前的元素。

1 个回答

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

撰写回答