码迷,mamicode.com
首页 > 编程语言 > 详细

python 小程序,在列表中找到所有指定内容的位置

时间:2016-08-31 22:09:28      阅读:164      评论:0      收藏:0      [点我收藏+]

标签:

要求如下图所示:

技术分享

 1 #!/usr/bin/python
 2 # -*- coding=UTF-8 -*-
 3 
 4 list=[‘10‘,‘11‘,‘xx‘,‘13‘,‘14‘,‘xx‘,‘16‘,‘17‘,‘xx‘,‘19‘]
 5 print ‘\n    原始数据为:‘,list,‘\n‘
 6 list_count=list.count(‘xx‘)
 7 y=0
 8 for i in range(list_count):
 9     list_tmp=list[y:]
10     y+=list_tmp.index(‘xx‘)+1
11     print ‘\t第‘,i+1,‘个 xx 位置是:‘,y,‘\n‘

 

python 小程序,在列表中找到所有指定内容的位置

标签:

原文地址:http://www.cnblogs.com/www1707/p/5827699.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!