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.

दोन 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 करा, मग पुढच्या ओळीत त्या sorted list म्हणून print करा.

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