python zip函数转制_Python中的Zip函数可更改为新的字符集。

给定一个26个字母的字符集,这里我们使用一个新的字符集。还有另一个字符集,就像字母集(a,b,c ........ z)一样,那么我们的任务是在新字符集和该字母集之间建立关系。

示例New character set: qwertyuiopasdfghjklzxcvbnm

Input: "wwmm"

Output: bbzy

算法Step 1: Given a new character set and input the string to make a relation.

Step 2: and the original character set also given below.

Step 3: Create a dictionary, we use here map technique, we map the English character set and new given character set, zip() does it for us. Both character sets are the map, here we match each character of given character set with each character of new charset sequentially.

Step 4: iterate through the original string and get characters of an original character set.

Step 5: join characters without space to get new string.

范例程式码# Function to change string to a new character

defnewString(cs,n):

ori = 'abcdefghijklmnopqrstuvwxyz'

newchar = dict(zip(cs,ori))

newstr = [newchar[chr] for chr in n]

print (''.join(newstr))

# Driver program

if __name__ == "__main__":

newcharSet = 'qwertyuiopasdfghjklzxcvbnm'

input = 'wwmn'

newString(newcharSet,input)

输出结果bbzy

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值