অর্ডার করা অভিধানের শুরুতে উপাদানগুলি সন্নিবেশ করার প্রয়োজন হলে, 'আপডেট' পদ্ধতি ব্যবহার করা যেতে পারে।
নীচে একই −
এর প্রদর্শন করা হলউদাহরণ
from collections import OrderedDict
my_ordered_dict = OrderedDict([('Will', '1'), ('James', '2'), ('Rob', '4')])
print("The dictionary is :")
print(my_ordered_dict)
my_ordered_dict.update({'Mark':'7'})
my_ordered_dict.move_to_end('Mark', last = False)
print("The resultant dictionary is : ")
print(my_ordered_dict) আউটপুট
The dictionary is :
OrderedDict([('Will', '1'), ('James', '2'), ('Rob', '4')])
The resultant dictionary is :
OrderedDict([('Mark', '7'), ('Will', '1'), ('James', '2'), ('Rob', '4')]) ব্যাখ্যা
-
প্রয়োজনীয় প্যাকেজগুলি আমদানি করা হয়৷
-
OrderedDict’ ব্যবহার করে একটি অর্ডার করা অভিধান তৈরি করা হয়েছে।
-
এটি কনসোলে প্রদর্শিত হয়৷
৷ -
কী এবং মান নির্দিষ্ট করতে 'আপডেট' পদ্ধতি ব্যবহার করা হয়।
-
'move_to_end' পদ্ধতিটি একটি মূল মান জোড়াকে শেষ পর্যন্ত নিয়ে যেতে ব্যবহৃত হয়।
-
আউটপুট কনসোলে প্রদর্শিত হয়।