My first attempt at python

Jason Stewart kahuna01 at hotmail.com
Fri Dec 8 07:02:37 EST 2000


Greetings,
	This is the first piece of code that I wrote in Python. So far
I think that Python is wonderful. Being inexperienced as I am in
python, I would like your help in analyzing my code and telling me
where I can improve. 
	This same functionality might be in a module somewhere, but I
wrote it for practice. Its a string tokenizer. If you could analyze it
and tell me where I could improve I would be grateful.

Thanks,
Jason

def tokenize(string_to_chop):
	"Break a string up into individual words"
	last_space = 0
	token = []
	for index in range(len(string_to_chop)):
		if string_to_chop[index:index+1] == " ":
			token.append(string_to_chop[last_space:index])
			last_space =  index + 1
		elif (index+1 == len(string_to_chop)):
		    token.append(string_to_chop[last_space:index+1])
	return token




More information about the Python-list mailing list