collections मॉड्यूल विशेष कंटेनर प्रकार प्रदान करता है जो बिल्ट-इन list/dict/tuple को सुविधाजनक, अक्सर अधिक कुशल विकल्प के साथ बढ़ाते हैं जो सामान्य पैटर्न के लिए हैं। उन्हें जानने से आप स्वच्छ, तेजी से कोड लिख सकते हैं।
defaultdict — स्वचालित डिफ़ॉल्ट मानों के साथ dicts
collections defaultdict
groups = {}
item items:
item.category groups:
groups[item.category] = []
groups[item.category].append(item)
groups = defaultdict()
item items:
groups[item.category].append(item)
