Le Thu, 8 Jan 2009 11:34:49 -0500, "Michael Langford" <michael.langf...@gmail.com> a écrit :
> Here is your algorithm made more pythonic. Notice the use of default > parameters, doc strings, not abbreviated variable names, unix C style > capitolization (very subjective, but often the one found in python > libs), the avoidance of control variables when possible, the use of > ascii_lowercase instead of your own string and the not calling > functions main that aren't __main__. > > #!/usr/bin/env python > import string > import random > > def rand_string(length = 5): > """returns a random string of numbers""" > return ''.join(random.sample(string.ascii_lowercase,length)) Since you wish to use (not necessary) optional args, it may be worth defining def rand_string(length = 5): """returns a random string of numbers""" return ''.join(random.sample(string.ascii_lowercase,length)) which also avoids reading string.ascii_lowercase in each loop denis _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor