python里字符串的缩写_在python中查找字符串中的缩写

乔恩·克莱门斯的解决方案是正确的,但这里有另一个解决方案。在

为了保持秩序,我不得不把钥匙单列出来。如果我用vdCacheType.keys()列出它们,它们是按如下顺序排列的:['R', 'C', 'WT', 'WB', 'NR', 'AWB', 'D', 'RA']这行不通。在

str.strip()在这种情况下不起作用,因为字符串之间没有空格。在vdCacheType = {'AWB' : 'Always WriteBack', 'WB': 'Write Back',

'NR': 'No Read Ahead', 'RA': 'Read Ahead Adaptive',

'WT': 'Write Through', 'R' : 'Read Ahead Always',

'D': 'Direct IO', 'C': 'Cached' }

vdCacheKeys = ['AWB','WB','NR','RA','WT','R','D','C']

mystr = 'NRWTD'

my2str = 'RAWBC'

listAbbr = []

result = ''

index = 0

print vdCacheType.keys()

for x in vdCacheKeys:

if x in mystr:

listAbbr.append(x)

index = mystr.find(x)

mystr = mystr[:index]+' ' + mystr[index +len(x):]

print mystr

result+=vdCacheType[x] + ', '

# print x # Here i would save the found abbr. in a list for later use

print result

输出No Read Ahead, Write Through, Direct IO,

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值