Greetings,
 
I'm an instructor of Computer Science at Loyola University, Chicago, and I and 
Dr. Harrington (copied on this email) teach sections of COMP 150, Introduction 
to Computing, using Python 3.  One of the concepts we teach students is the str 
methods split() and join().  I have a suggestion for a small addition to the 
list class: add a join() method to lists.  It would work in a similar way to 
how join works for str's, except that the object and method parameter would be 
reversed: <list object>.join(<str object>).
 
Rationale: When I teach students about split(), I can intuitively tell them 
split() splits the string on its left on white space or a specified string.  
Explaining the current str join() method to them doesn't seem to make as much 
sense: use the string on the left to join the items in the list??  If the list 
class had a join method, it would be more intuitive to say "join the items in 
the list using the specified string (the method's argument)."  This is similar 
to Scala's List mkString() method.
 
I've attached a proposed implementation in Python code which is a little more 
general than what I've described.  In this implementation the list can contain 
elements of any type, and the separator can also be any data type, not just str.
 
I've noticed that the str join() method takes an iterable, so in the most 
general case I'm suggesting to add a join() method to every Python-provided 
iterable (however, for split() vs. join() it would be sufficient to just add a 
join() method to the list class).
 
Please let me know your ideas, reactions, and comments on this suggestion.
 
Thanks and regards,
Dr. Robert (Bob) Yacobellis

Attachment: join.py
Description: Binary data


Attachment: jointest.py
Description: Binary data

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to