একটি স্ট্রিং-এ থাকা শব্দগুলোর ক্রম উল্টিয়ে নতুন স্ট্রিং তৈরি করা। split() এবং reversed() ফাংশন ব্যবহার করে সহজে করা যায়।
নমুনা টেস্ট কেস
Input: "I am a python programmer" Output: programmer python a am I Input: "tutorialspoint is a educational website" Output: website educational a is tutorialspoint
অ্যালগরিদম
১. স্ট্রিং ইনিশিয়ালাইজ করুন। ২. split() দিয়ে স্পেস দিয়ে ভাগ করুন → words লিস্ট। ৩. reversed(words) দিয়ে উল্টান। ৪. list() দিয়ে লিস্টে কনভার্ট। ৫. " ".join() দিয়ে জড়িয়ে প্রিন্ট।
উদাহরণ ১
string = "I am a python programmer"
words = string.split()
words = list(reversed(words))
print(" ".join(words))
আউটপুট
programmer python a am I
উদাহরণ ২
string = "tutorialspoint is a educational website"
words = string.split()
words = list(reversed(words))
print(" ".join(words))
আউটপুট
website educational a is tutorialspoint
উপসংহার
split() এবং reversed() কম্বিনেশন দিয়ে শব্দ উল্টানো খুব সহজ। প্রশ্ন থাকলে কমেন্ট করুন।