Demo entry 6623387

pythonic_vs_upythonic

   

Submitted by pythonic.libresoft.info on Jun 07, 2017 at 16:11
Language: Python. Code size: 467 Bytes.

colors = ["blue", "green", "yellow"]
colors_dict = {}

print "Hello SATToSe";
for i in range(len(colors)):
	print str(i) + " " + colors[i]
	try:
		colors_dict[colors[i]] += 1
	except:
		colors_dict[colors[i]] = 1

print colors_dict
	

from collections import defaultdict

colors = ["blue", "green", "yellow"]
colors_dict = defaultdict(int)

print "Hello SATToSe"
for index, color in enumerate(colors):
	print index, color
	colors_dict[color] += 1
print colors_dict

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).