Lesson 20 of 34

Sets: শুধু অনন্য Values

7 min 25 XP

Set কখনো একই value দুবার রাখে না। List থেকে duplicates বাদ দেওয়ার সবচেয়ে সহজ উপায় set()।

Example: edit me and press Run

Output Loading Python (first time takes a few seconds)
Press Run to see the result here.

দুটি set তুলনা করুন: | (union) সব কিছু, & (intersection) যা দুটোতেই আছে, আর - (difference) যা শুধু প্রথমটিতে আছে।

Example: edit me and press Run

Output Loading Python (first time takes a few seconds)
Press Run to see the result here.

Set-এ কোনো ক্রম নেই, তাই set[0] কাজ করে না। ক্রমে চাইলে sorted() ব্যবহার করুন।

Challenge

+25 XP

nums = [5, 3, 5, 1, 3, 9, 1]। কতগুলো অনন্য সংখ্যা আছে print করুন, তারপর পরের লাইনে সেগুলো sorted list হিসেবে print করুন।

Output Loading Python (first time takes a few seconds)
Press Run to see the result here.