Making dictionary construction shorter in Python using defaultdict? -


is there anyway can make code-block shorter? seems written more efficiently:

combs = defaultdict(list) zf in zipfiles:     chunks = zf.split('_')     combs[chunks[0] + '_' + chunks[1]].append(zf) 

maybe searching this:

combs = defaultdict(list) zf in zipfiles:     combs["_".join(zip.split("_")[0:2]].append(zf) 

Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -