Python 查找list中的某个元素的所有的下标方法

作者:xuejinliang 时间:2022-10-15 21:48:16 

如下所示:


#!/usr/bin/env python
#_*_ coding:utf-8 _*_
name = ['hello', 'world', 'a', 'b', 'c', 1, 2, 3, 'hello', 'world', 'a', 'b', 'c', 1, 2, 3]
first_pos = 0
for i in range(name.count(2)):
new_list = name[first_pos:]
next_pos = new_list.index(2) + 1
print 'find ', first_pos + new_list.index(2)
first_pos += next_pos

note:查找出列表中所有的某个元素

来源:https://blog.csdn.net/xuejinliang/article/details/51591951

标签:python,list,元素,下标
0
投稿

猜你喜欢

  • Go语言string,int,int64 ,float之间类型转换方法

    2023-06-28 15:20:30
  • 详解Python:面向对象编程

    2023-10-26 16:17:53
  • python实时获取外部程序输出结果的方法

    2023-04-27 02:29:04
  • Python使用PIL模块生成随机验证码

    2022-03-05 21:54:11
  • PLSQLDeveloper登录远程连接Oracle的操作

    2023-07-23 03:34:22
  • python处理csv数据动态显示曲线实例代码

    2022-05-01 00:35:05
  • 基于layer.js实现收货地址弹框选择然后返回相应的地址信息

    2024-05-08 09:32:22
  • 15个短代码示例理解python丰富的编程思维

    2022-07-18 08:16:57
  • 如何将Python字符串转换为JSON的实现方法

    2022-07-11 02:58:37
  • Sub-Pixel Bug?!

    2010-03-24 18:09:00
  • Python爬虫设置ip代理过程解析

    2021-05-27 15:08:30
  • pandas中的ExcelWriter和ExcelFile的实现方法

    2023-09-20 00:10:36
  • MySQL数据库表修复 MyISAM

    2024-01-19 16:39:08
  • 用javascript实现select的美化

    2007-05-11 16:50:00
  • golang 使用sort.slice包实现对象list排序

    2023-06-21 18:25:46
  • pandas.DataFrame的for循环迭代的实现

    2023-07-07 22:10:28
  • python+pytest自动化测试函数测试类测试方法的封装

    2021-12-26 21:03:14
  • 详解Django中类视图使用装饰器的方式

    2023-12-20 15:35:57
  • 对PyTorch中inplace字段的全面理解

    2022-11-15 13:52:24
  • python爬取之json、pickle与shelve库的深入讲解

    2023-11-05 00:58:35
  • asp之家 网络编程 m.aspxhome.com