itertools.permutations ব্যবহার
বাক্যের শব্দগুলোর সব সম্ভাব্য পারমিউটেশন তৈরি করতে itertools.permutations ব্যবহার করুন।
উদাহরণ কোড
from itertools import permutations
def calculate_permutations(my_string):
my_list = list(my_string.split())
permutes = permutations(my_list)
for i in permutes:
permute_list = list(i)
for j in permute_list:
print(j)
print()
my_string = "hi there"
print("The string is :")
print(my_string)
print("All possible permutation are :")
calculate_permutations(my_string)
আউটপুট
The string is : hi there All possible permutation are : hi there there hi
ব্যাখ্যা
প্রয়োজনীয় প্যাকেজ ইম্পোর্ট করা হয়।
‘calculate_permutations’ ফাংশন স্ট্রিংকে শব্দে ভাগ করে লিস্টে রূপান্তর করে।
পারমিউটেশন তৈরি করে প্রতিটি কনসোলে প্রিন্ট করে।
বহিরাগত স্ট্রিং সংজ্ঞায়িত করে ফাংশন কল করা হয়।