[Tutor] how to alter list content

w chun wescpy at gmail.com
Fri Oct 14 04:07:30 CEST 2005


combining the best of both worlds of nick using a faster list comp and brett
using os.path.splitext():

>>> files = ['DSC00001.JPG', 'DSC00002.JPG', 'DSC00003.JPG']
>>> newFiles = [os.path.splitext(f)[0] for f in files]
>>> print newFiles
['DSC00001', 'DSC00002', 'DSC00003']

cheers,
-- wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Core Python Programming", Prentice Hall, (c)2006,2001
http://corepython.com

wesley.j.chun :: wescpy-at-gmail.com <http://wescpy-at-gmail.com>
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20051013/c6c9bc64/attachment.html


More information about the Tutor mailing list