对于'列表'中的'元素'(但不包括元素X)
问题描述:
我需要遍历列表,但错过列表中的特定元素,有没有快速的方法来做到这一点?对于'列表'中的'元素'(但不包括元素X)
list = ['X','Y','Z']
for element in list (but not including element 'X'):
print(element)
>>>Y
>>>Z
答
seq = ['X','Y','Z']
for element in seq:
if element == 'X':
continue
print(element)