কম্পিউটার

একটি নতুন অক্ষর সেটে পরিবর্তন করতে পাইথনে জিপ ফাংশন।


একটি 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

  1. পাইথনে issubset() ফাংশন

  2. ইন্টারসেকশন() ফাংশন পাইথন

  3. পাইথনে একটি ফাংশনে ডিফল্ট প্যারামিটার মান কিভাবে সেট করবেন?

  4. পাইথনে ছোট হাতের সমস্ত ফাংশন আর্গুমেন্ট কিভাবে পরিবর্তন করবেন?