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
热门推荐
10 医院探望朋友祝福语简短
11 毕业祝福语简短女朋友
12 春节虎年爸妈祝福语简短
13 儿童毕业祝福语 简短6
14 开工仪式横幅祝福语简短
15 孩子日常祝福语大全简短
16 清晨寄语诗句祝福语简短
17 结婚送亲认亲祝福语简短
18 虎年喝酒拜年祝福语简短