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
Post a Comment