从字符串列表中删除项目 [英] remove an item from string list
本文介绍了从字符串列表中删除项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个字符串列表
items = [''B'',''D'',''B'',''A'',''E '']
假设我不知道这些项目的订单(索引)。我想删除列表中的第二个B而不排序[使用items.sort()]或更改列表中其他项的顺序。我怎么能这样做?
remove()和pop(),只取第一个''B''或者我必须知道第二个''B'的索引'删除第二个''B''。
I have a string list
items = [''B'',''D'',''B'',''A'',''E'']
Assume that I don''t know the order (index) of these items. I would like to remove the second ''B'' out of the list without sorting [using items.sort() ] or changing the the order of other items in the list. How can I do that?
The remove() and pop(), only take the first ''B'' or I have to know the index of the second ''B'' to remove second ''B'' out.
推荐答案
我有一个字符串列表
items = [''B'',''D'',''B'',''A'',''E'']
假设我不知道这些项目的顺序(索引)。我想删除列表中的第二个B而不排序[使用items.sort()]或更改列表中其他项的顺序。我怎么能这样做?
remove()和pop(),只取第一个''B''或者我必须知道第二个''B'的索引'删除第二个''B''。
I have a string list
items = [''B'',''D'',''B'',''A'',''E'']
Assume that I don''t know the order (index) of these items. I would like to remove the second ''B'' out of the list without sorting [using items.sort() ] or changing the the order of other items in the list. How can I do that?
The remove() and pop(), only take the first ''B'' or I have to know the index of the second ''B'' to remove second ''B'' out.
展开 | 选择 < span class =codeDivider> | Wrap | 行号
展开 | 选择 | Wrap | 行号
展开 | 选择 | 换行 | 行号
这篇关于从字符串列表中删除项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文