list的相关操作 - 单词倒排 - 统计个数
2016-08-05 15:19
211 查看
#!/usr/bin/python
#---------------单词倒排----------------
def str_reverse(str_src):
# 以空格为分隔符,将各单词取出来存放在list中
str_dst = str_src.split()
# 同理若想以","为分隔符去单词就用 str_dst = str_src.split(",")
print str_dst
# 反转list0
str_dst.reverse()
print str_dst
return str_dst
if __name__ == '__main__':
for str_out in str_reverse(raw_input("please input your sentense:")):
print str_out,
# 另倒排也可利用切片:eg
A = ['abc', 123, 456, 'def']
B = A[::-1]
print B
#---------------统计个数----------------
A="a=1, b=2, c=3, cc=4, cc=5"
count = index = 0
while True:
# 在 A 中找 cc
index = A.find("cc")
# 若没找到
if index == -1:
break
else:
# A 取该次出现的位置后面的字符串
A = A[ index + 1: ]
count += 1
print "count: %d" % count
#---------------单词倒排----------------
def str_reverse(str_src):
# 以空格为分隔符,将各单词取出来存放在list中
str_dst = str_src.split()
# 同理若想以","为分隔符去单词就用 str_dst = str_src.split(",")
print str_dst
# 反转list0
str_dst.reverse()
print str_dst
return str_dst
if __name__ == '__main__':
for str_out in str_reverse(raw_input("please input your sentense:")):
print str_out,
# 另倒排也可利用切片:eg
A = ['abc', 123, 456, 'def']
B = A[::-1]
print B
#---------------统计个数----------------
A="a=1, b=2, c=3, cc=4, cc=5"
count = index = 0
while True:
# 在 A 中找 cc
index = A.find("cc")
# 若没找到
if index == -1:
break
else:
# A 取该次出现的位置后面的字符串
A = A[ index + 1: ]
count += 1
print "count: %d" % count
相关文章推荐
- 字符串相关的操作练习 翻转单词;统计单词数;逆向输出单词串
- 利用List统计文件中单词个数,并排序输出
- 驱动中的LIST_ENTRY操作相关函数
- R-往一个list某列中写入新的数据append(),查找列名 names(sapply()及list相关操作
- 文件操作:洗牌/统计文本文件单词/复制mp3文件/多个文件合并成一个文件
- CheckBoxList的相关操作
- linux中list结构应用及构造hashtable进行英文文章单词数统计
- 【字符串操作】01.统计一个字符串中单词的个数
- Collection、List、Set和Map的相关操作的区别
- map相关操作:map遍历,map转换为list
- 数据统计例子,相关子查询!(SQL 中循环操作一列数据方法)
- 清空ArrayList所引发的思考(List相关操作)
- 关于c# 泛型List集合对象的用法及相关操作
- 数据统计例子,相关子查询!(SQL 中循环操作一列数据方法)
- 清空ArrayList所引发的思考(List相关操作)
- SQL Server 统计信息相关操作(转)
- C++ list链表相关操作
- c++实现循环单链表的相关操作(创建,插入,删除,保序插入,统计结点)
- 三:redis的List类型相关操作
- 统计英文文章单词数相关内容