suggestion for a small addition to the Python 3 list class

Robert Yacobellis ryacobellis at luc.edu
Sun Apr 21 10:09:20 EDT 2013


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20130421/175b9c31/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: join.py
Type: application/octet-stream
Size: 651 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20130421/175b9c31/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: jointest.py
Type: application/octet-stream
Size: 1247 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20130421/175b9c31/attachment-0001.obj>


More information about the Python-list mailing list