首页 技术 正文
技术 2022年11月17日
0 收藏 529 点赞 4,886 浏览 681 个字

1、将一串字符串反向输出,如将”abcd”变成“dcba”

str1="abcd"
print str1[::-1]

2、判断是否为回文——判断用户输入的字符串是否为回文。回文是指正反拼写形式都是一样的词,譬如“racecar”。

while(1):
input_str = raw_input("please input your string:")
if input_str=="quit":
print "bye"
break
elif input_str==input_str[::-1]:
print "your input is huiwen"
else:
print "your input is not huiwen"

3、统计一段英文语句的字母个数:

#!coding=utf-8
txt="Failure is probably the fortification in your pole"
count={}
for i in txt:
count.setdefault(i,0)#如果字典中没有key为i的键,则添加这个键,并设置该键的值为0。如果已经有这个键了,则不更改该字典
count[i]=count[i]+1
print count

4、统计一段英文语句中单词的个数:

#!coding=utf-8
txt="Failure is probably the fortification in your pole is"
strlist=txt.split(" ")
countWord={}
for i in strlist:
countWord.setdefault(i,0)
countWord[i]=countWord[i]+1
print countWord

  

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,000
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,512
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,358
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,141
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,771
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,849