[Tutor] how to alter list content
Nick Lunt
nick at javacat.f2s.com
Thu Oct 13 23:48:20 CEST 2005
Hi marc,
>
> i create a list of all JPG files with:
> >>> list = glob.glob('*.JPG')
> the content of 'list' is now:
> >>> print list
> ['DSC00001.JPG', 'DSC00002.JPG', 'DSC00003.JPG']
>
> but what i want is this type of list:
> ['DSC00001', 'DSC00002', 'DSC00003']
> i.e. the names w/o the file extension.
>
> what's the easiest way of doing this?
>
> marc
You need the split() method.
ie
>> l = ['DSC00001.JPG', 'DSC00002.JPG', 'DSC00003.JPG']
>> print [i.split('.')[0] for i in l]
Hth,
Nick .
More information about the Tutor
mailing list