collections મોડ્યુલ વિશેષ કન્ટેનર પ્રકાર પ્રદાન કરે છે જે બિલ્ટ-ઇન list/dict/tuple ને સુવિધાજનક અને ઘણીવાર સામાન્ય પેટર્ન માટે વધુ કાર્યક્ષમ વિકલ્પ સાથે વિસ્તૃત કરે છે. તેમને જાણવાથી તમે સ્વચ્છ અને વધુ ઝડપી કોડ લખી શકો છો.
defaultdict — આપોઆપ ડિફોલ્ટ મૂલ્યો સાથે dict
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)
