2024-10-02 00:29:48 发布
网友
我得到了一个不同字符串的列表。他们中的许多人在f.e.“X”中有一个特殊的角色。如何在python中从列表中删除获取特定字符的字符串
f.e。 ['ABCXDU'、'ZUTRC'、'AZUX'、'ABNIU'] 我想要的输出-->;该列表的字符串中没有x
使用
[x for x in some_list if "X" not in x]
创建一个新的列表,其中只包含那些没有X的内容
X
new_list = [s for s in your_input_list if 'X' not in s]
或者你可以这样做:
new_list = list(filter(lambda s: 'X' not in s, your_input_list))
您可以使用列表理解
new_list = [item for item in my_list if "X" not in item]
使用
创建一个新的列表,其中只包含那些没有
X
的内容或者你可以这样做:
您可以使用列表理解
new_list = [item for item in my_list if "X" not in item]
相关问题 更多 >
编程相关推荐