n00bie wants advice.

bsagert at gmail.com bsagert at gmail.com
Wed Jul 2 02:25:53 EDT 2008


This simple script writes html color codes that can be viewed in a
browser.  I used short form hex codes (fff or 000, etc) and my list
has only six hex numbers otherwise the results get rather large. I
invite criticism as to whether my code is "pythonic". Are there other
ways to generate the hex combos besides the nested "for" loops? Thanks
in advance, Bill

list = ['3','6','9','b','d','f']

s = '<html><head><style>h1{margin:0}</style></head><body>\n'

for a in list:
	for b in list:
		for c in list:
			s += '<h1 style="background:#'+ a + b + c +'">'+ a + b + c +'</h1>
\n'

s += '</body></html>'

f = open('c:/x/test.htm', 'w')
f.write(s)
f.close()



More information about the Python-list mailing list