দেওয়া টাপলের লিস্ট থেকে ডুপ্লিকেট ফার্স্ট ভ্যালু বিশিষ্ট টাপল রিমুভ করতে একটি সিম্পল 'for' লুপ, এবং 'add' ও 'append' মেথড ব্যবহার করা যায়।
নিচে ডেমোстран্স্ট্রেশন দেওয়া হলো:
উদাহরণ
my_input = [(45.324, 'Hi Jane, how are you'), (34252.85832, 'Hope you are good'), (45.324, 'You are the best.')]
visited_data = set()
my_output_list = []
for a, b in my_input:
if a not in visited_data:
visited_data.add(a)
my_output_list.append((a, b))
print("The list of tuple is : ")
print(my_input)
print("The list of tuple after removing duplicates is :")
print(my_output_list)
আউটপুট
The list of tuple is : [(45.324, 'Hi Jane, how are you'), (34252.85832, 'Hope you are good'), (45.324, 'You are the best.')] The list of tuple after removing duplicates is : [(45.324, 'Hi Jane, how are you'), (34252.85832, 'Hope you are good')]
ব্যাখ্যা
- একটি টাপলের লিস্ট সংজ্ঞায়িত করা হয়েছে, এবং কনসোলে ডিসপ্লে করা হয়েছে।
- একটি খালি সেট এবং একটি খালি লিস্ট তৈরি করা হয়েছে।
- টাপলের লিস্টের ওপর ইটারেট করা হয়েছে, এবং যদি সেটিতে না থাকে, তবে সেটিতে যোগ করা হয়েছে, এবং লিস্টটিতে ও অ্যাপেন্ড করা হয়েছে।
- এটি আউটপুট হিসেবে কনসোলে ডিসপ্লে করা হয়েছে।