# P4.4 Python Sets: Duplicates काढा आणि Groups compare करा

Source: https://ravindrabagale.com/mr/datascience/py04-python-lists-tuples-dictionaries-and-sets-with-examples/p4-4-python-sets-remove-duplicates-and-compare-groups.html
Language: mr (Marathi with English technical terms)

हे का शिकायचं?

किती वेगळ्या cities मधून orders आल्या किंवा दोन्ही महिन्यांत कोण customer आला — sets हे झटपट सांगतात.

हे काय आहे?

Set मध्ये प्रत्येक value एकदाच असते आणि क्रम नसतो. & दोन्हीत असलेल्या, | सगळ्या आणि - फक्त पहिल्यात असलेल्या values देतो.

कसं करायचं?

Step 1. set(list) ने duplicates काढा.
Step 2. &, |, - ने groups compare करा.

उदाहरण A: Unique cities

```python
cities = ["Madrid", "Seville", "Madrid", "Valencia", "Seville"]
unique = set(cities)
print(len(unique))
print(sorted(unique))
```

Output:

```text
3
['Madrid', 'Seville', 'Valencia']
```

याचा अर्थ: set() ने duplicate cities निघून गेल्या.

उदाहरण B: दोन्ही महिन्यांतले customers

```python
jan = {"C1", "C2", "C3", "C4"}
feb = {"C3", "C4", "C5"}
print(sorted(jan & feb))
print(sorted(jan - feb))
print(sorted(jan | feb))
```

Output:

```text
['C3', 'C4']
['C1', 'C2']
['C1', 'C2', 'C3', 'C4', 'C5']
```

याचा अर्थ: & ने दोन्ही sets मध्ये असलेले customers मिळाले.

रवींद्र बागले यांची tip

"Unique" आणि "कोण गायब आहे" या प्रश्नांसाठी sets वापरा. List मध्ये एकेक item तपासण्यापेक्षा हे खूप जलद आहे.
