Lesson 20 of 34

Sets: ప్రత్యేక విలువలు మాత్రమే

7 min 25 XP

set లో ఒకే విలువ రెండుసార్లు ఉండదు. list నుండి పునరావృతాలను తీసేయడానికి 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.

Sets కి క్రమం ఉండదు, కాబట్టి set[0] పనిచేయదు. క్రమంలో కావాలంటే sorted() వాడండి.

Challenge

+25 XP

nums = [5, 3, 5, 1, 3, 9, 1]. ఎన్ని ప్రత్యేక సంఖ్యలు ఉన్నాయో print చేసి, తర్వాతి లైన్‌లో వాటిని క్రమమైన list గా print చేయండి.

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