Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > alt.comp.programming > #246

[Web Feed] Python’s defaultdict is an incredibly useful tool to specify default values for missing keys (RealPython has a great primer on them).

I

Subject [Web Feed] Python’s defaultdict is an incredibly useful tool to specify default values for missing keys (RealPython has a great primer on them).

I
Newsgroups alt.comp.programming
Message-Id <1615640069.O2BdUIVU8kCJP6IN0zpzU8ZmkKHS8AfS@somewhere.cbr>
Date 2021-03-13 12:55 +0000
Organization Usenet.Farm
From Feed Supplier <feed.supplier@somewhere.cbr>

Show all headers | View raw


<blockquote>
Python’s 
<code>
defaultdict
</code>
 is an incredibly useful tool to specify default values for missing keys (RealPython has a great primer on them).

I found I was taking up so much memory to store the value 0 for an algorithm which counted rather infrequent elements in a huge sequence split into many chunks. Using a 
<code>
defaultdict(int)
</code>
 for each distinct element to store which indices had a non-zero count of the respective element greatly optimised it, but I yearned for a 
<code>
defaultlist
</code>
 equivalent to standardise this approach and generally make my code more expressive.
</blockquote>

<u>Link 1</u>
https://blog.matthewbarber.io/2020/12/08/defaultlist

Back to alt.comp.programming | Previous | Next | Find similar


Thread

[Web Feed] Python’s defaultdict is an incredibly useful tool to specify default values for missing keys (RealPython has a great primer on them).&#xA;&#xA;I Feed Supplier <feed.supplier@somewhere.cbr> - 2021-03-13 12:55 +0000

csiph-web