python判断是相邻数字_(python 怎么去除相邻连续的数字)

python 怎么去除相邻连续的数字

用列表解析,比如:

b=[1001,1002,1003,1004,1005]

[x for x in b if b.index(x)%2 ==0] 就是你要的结果,实际就是取列表中奇数位的值

请把下面代码转换为python语言的代码,功能为把数字用汉字表示(如1001表示为一千零一)

#coding:gbk

import math

units=["", "十", "", "千", "万", "十", "百", "千", "亿", "十", "百", "千"]

nums=["","一", "二", "三", "四", "五","六", "七", "八", "九"]

def translate(num):

num=str(num)

res=''

for p in xrange(len(num)-1,-1,-1):

r=int(int(num)/math.pow(10,p))

print r,p

res =nums[r] units[p]

for (i,j) in [('零十','零'), ('零百','零'), ('零千','零')]:

res=res.replace(i,j)

while res.find('')!=-1:

res=res.replace('零零','零')

for (i,j) in [('零万','万'),('零亿','亿')]:

res=res.replace(i,j)

res=res.replace('亿万','亿')

if res.startswith('一十'):

res=res[2:]

if res.endswith('零'):

res=res[:-2]

return res

print(translate('1000000010'))

好丑的代码……

如何利用python语言中list和range结合起来使用

使用举例:

nums = [] #定义一个list

for i in range(1, 1001): //使用range的值循环加到nums中

nums.append(i)

python怎么比较字典中的元素

i={1:"192.168.0.1:1000",2:"192.168.0.1:1000",3:"192.168.0.1:1000",4:"192.168.0.1:1001",5:"192.168.0.1:1001",6:"192.168.0.1:1002",7:"192.168.0.1:1003"}

for f in range(1,8):

a=i[f]

for w in range(2,8):

b=i[w]

if a==b and f!=w:

print f,w

的作一典

版权声明:本站所有文章皆为原创,欢迎转载或转发,请保留网站地址和作者信息。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值