从列表中切出特定内容 [英] Slicing out a specific from a list

查看:33
本文介绍了从列表中切出特定内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只有一个列表,我想打印出其中的所有元素,但要跳过一个特定的列表.

I have one list and I want to print out all elements of it but skip one specific.

a = [1,2,3,4,5,6,7,8,9]

我要打印出来:

1,3,4,5,6,7,8,9 

(在类似于常规for循环的列中)

(in a column like a regular for-loop)

这可能吗?

推荐答案

  1. 如果您指定要通过其位置(索引)跳过的元素:

for position, element in enumerate(a):
    if position != specified_position:
        print(element)

  • 如果您指定要通过其值跳过的元素:

    for element in a:
        if element != specified_value:
            print(element)
    

  • 这篇关于从列表中切出特定内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆