[Python] life game(in 1-dimention)

#!/usr/bin/env python
import random
import time

CNT=151
delay=0.2
empty='.'
fill='#'

"""get console's size"""
import os
rows,cols=os.popen('stty size','r').read().split()
CNT=int(cols)
del rows,cols
"""get console's size end"""


def cnt(index):
	global before
	num=0
	for i in range(index-1,index+2):
		if before[i%CNT]==fill:
			num+=1
	return num

#lst=[random.choice(['#','.']) for i in range(CNT)]
lst=[empty for i in range(CNT)]
for i in random.sample(range(CNT),5):
	lst[i]=fill
before=[]
while True:
	print ''.join(lst)
	before=lst[:]
	for i in range(CNT):
		if cnt(i) in [1,2]:
			lst[i]=fill
		else:
			lst[i]=empty
	time.sleep(delay)

[Python] permutation

[code lang=”python”]
#!/usr/bin/python
def perm(a,b=[]):
if not len(a):
print ”.join(b)
for i in range(len(a)):
b.append(a.pop(i))
perm(a,b)
a.insert(i,b.pop())
perm(list("abcd"))
[/code]

abcd
abdc
acbd
acdb
adbc
adcb
bacd
badc
bcad
bcda
bdac
bdca
cabd
cadb
cbad
cbda
cdab
cdba
dabc
dacb
dbac
dbca
dcab
dcba