获取python列表中字符的索引 [英] get index of character in python list
本文介绍了获取python列表中字符的索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在包含多个字符的列表中查找指定字符的索引的最佳方法是什么?
What would be the best way to find the index of a specified character in a list containing multiple characters?
推荐答案
>>> ['a', 'b'].index('b')
1
如果列表已经排序,那么您当然可以比线性搜索做得更好。
If the list is already sorted, you can of course do better than linear search.
这篇关于获取python列表中字符的索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文