Lesson 20 of 34

Sets: மீண்டும் வராத மதிப்புகள்Sets: Unique Values Only

7 min 25 XP

set-ல் ஒரே மதிப்பு இரண்டு முறை இருக்காது. ஒரு list-லிருந்து நகல்களை (duplicates) நீக்க set() மிக எளிய வழி.

A set never holds the same value twice. set() is the easiest way to remove duplicates from a list.

Example: edit me and press Run

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

இரண்டு sets-ஐ ஒப்பிடலாம்: | (union) இரண்டிலும் உள்ள அனைத்தும், & (intersection) இரண்டிலும் பொதுவானவை, - (difference) முதலில் மட்டும் உள்ளவை.

Compare two sets: | (union) is everything, & (intersection) is what both share, and - (difference) is what only the first has.

Example: edit me and press Run

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

set-க்கு வரிசை (order) இல்லை, எனவே set[0] வேலை செய்யாது. வரிசைப்படி வேண்டுமென்றால் sorted() பயன்படுத்துங்கள்.

Sets have no order, so set[0] doesn't work. Use sorted() when you need them in order.

Challenge

+25 XP

nums = [5, 3, 5, 1, 3, 9, 1]. முதல் வரியில் தனித்துவமான (unique) எண்களின் எண்ணிக்கையையும், இரண்டாவது வரியில் அவற்றை வரிசைப்படுத்திய list-ஆகவும் print செய்யுங்கள்.

nums = [5, 3, 5, 1, 3, 9, 1]. Print how many unique numbers there are, then print them as a sorted list on the next line.

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