Lesson 20 of 34

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

7 min 25 XP

set-ல் ஒரே மதிப்பு இரண்டு முறை இருக்காது. ஒரு 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.

இரண்டு sets-ஐ ஒப்பிடலாம்: | (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-க்கு வரிசை (order) இல்லை, எனவே set[0] வேலை செய்யாது. வரிசைப்படி வேண்டுமென்றால் sorted() பயன்படுத்துங்கள்.

Challenge

+25 XP

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

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