এখানে আমরা একটি ব্যবহারকারীর ইনপুট অ্যারে ব্যবহার করি এবং আমাদের উপাদানগুলির দৈর্ঘ্য অনুসারে তালিকাটি সাজাতে হবে। এখানে আমরা পাইথন ইনবিল্ট ফাংশন sorted().
ব্যবহার করিউদাহরণ
Input::[“mona”,”pp”,”aaa”] Lengths are [4,2,3] So, the sorted array should be [2,3,4] Output::[“pp”,”aaa”,”mona”]
অ্যালগরিদম
Step 1: Input list element. Step 2: apply sorted (A,len) function.
উদাহরণ কোড
# To sort a list
def sortedlist(A):
newlist = sorted(A, key=len)
return newlist
# Driver code
A=list()
n=int(input("Enter the size of the List ::"))
print("Enter the Element ::")
for i in range(int(n)):
k=input("")
A.append(k)
print("SORTED LIST ::>",sortedlist(A))
আউটপুট
Enter the size of the List ::5 Enter the Element :: mona gulli adwaita aadrika pinki SORTED LIST ::> ['mona', 'gulli', 'pinki', 'adwaita', 'aadrika']