Data Structures (List, Dict, Tuple, Sets)

इस ब्लॉग में हम Python के core data structures जैसे List, Dictionary, Tuple और Sets को विस्तार से सीखेंगे। ये Data Science और Generative AI projects के लिए fundamental हैं।

📦 Python Data Structures: List, Dictionary, Tuple & Sets

Python में data को organize और manipulate करने के लिए अलग-अलग data structures होते हैं। Data Science और AI में इनका सही इस्तेमाल करना बहुत जरूरी है। इस ब्लॉग में हम List, Dictionary, Tuple और Sets के बारे में विस्तार से सीखेंगे।

🔹 List (सूचियाँ)

List एक ordered collection है जिसमें multiple values रखी जा सकती हैं। Lists mutable होती हैं, यानी आप elements को change, add या delete कर सकते हैं।

  • Ordered and indexed
  • Mutable (changeable)
  • Supports duplicates
  • Use cases: storing datasets, sequences, stacking values
# Example
fruits = ["Apple", "Banana", "Cherry"]
fruits.append("Orange")
print(fruits[1])  # Banana
fruits.remove("Apple")
    

🔹 Dictionary (डिक्शनरी)

Dictionary key-value pairs का collection होता है। Keys unique होती हैं और values किसी भी data type की हो सकती हैं। Dictionaries unordered और mutable होती हैं।

  • Key-value mapping
  • Mutable and dynamic
  • Efficient data lookup
  • Use cases: storing configuration, JSON-like data, fast access
# Example
student = {"name":"Ds", "age":25, "course":"Data Science"}
print(student["name"])  # Ds
student["age"] = 26
student["city"] = "Delhi"
    

🔹 Tuple (टपल)

Tuple ordered और immutable collection है। एक बार tuple create हो जाने के बाद उसके elements change नहीं किए जा सकते। यह memory-efficient होता है और read-only data के लिए ideal है।

  • Ordered and indexed
  • Immutable (unchangeable)
  • Supports duplicates
  • Use cases: fixed dataset, return multiple values from functions
# Example
colors = ("Red", "Green", "Blue")
print(colors[0])  # Red
# colors[1] = "Yellow"  # Error, tuples are immutable
    

🔹 Sets (सेट्स)

Set unordered और mutable collection है, जिसमें unique elements होते हैं। Sets mathematical set operations के लिए बहुत useful हैं।

  • Unordered and unindexed
  • Unique elements only
  • Mutable
  • Use cases: removing duplicates, membership tests, union/intersection
# Example
numbers = {1, 2, 3, 3, 4}
numbers.add(5)
print(numbers)  # {1,2,3,4,5}
numbers.remove(2)
    

⚖️ Comparison

Structure Mutable Ordered Duplicates
ListYesYesYes
DictionaryYesNo (Python 3.7+ maintains insertion order)Keys No, Values Yes
TupleNoYesYes
SetYesNoNo

🏆 निष्कर्ष

Python के data structures जैसे List, Dictionary, Tuple और Sets Data Science और AI projects में data को efficiently store और manipulate करने के लिए essential हैं। Beginners को इनका proper understanding और practical application सीखना चाहिए ताकि data-driven projects में आसानी हो।