Re: Splitting a string into substrings of equal size

2009-08-15 Thread Rascal
I'm bored for posting this, but here it is: def add_commas(str): str_list = list(str) str_len = len(str) for i in range(3, str_len, 3): str_list.insert(str_len - i, ',') return ''.join(str_list) -- http://mail.python.org/mailman/listinfo/python-list

Re: Python 'for' loop is memory inefficient

2009-08-15 Thread Rascal
look at xrange -- http://docs.python.org/library/functions.html#xrange -- http://mail.python.org/mailman/listinfo/python-list

Re: Problem with join in__str__() in class (newbie)

2009-08-09 Thread jon rascal
def __str__(self):      output = '%s:%s' % (self.expert_id, self.name)      output += '\nKnown topics: %s' % (', '.join(str(self.topics))) You're turning your list into a string -- try this: ', '.join([str(x) for x in self.topics]) -- http://mail.python.org/mailman/listinfo/python-list