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.