Reputation: 7416
Is there anyway I can make this code-block shorter? It seems like something that could be written more efficiently:
combs = defaultdict(list)
for zf in zipfiles:
chunks = zf.split('_')
combs[chunks[0] + '_' + chunks[1]].append(zf)
Upvotes: 0
Views: 51
Reputation: 372
Maybe you are searching for this:
combs = defaultdict(list)
for zf in zipfiles:
combs["_".join(zip.split("_")[0:2]].append(zf)
Upvotes: 1